0
0
C++programming~20 mins

What is C++ - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
C++ Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of simple C++ program with variables
What is the output of this C++ program?
C++
#include <iostream>
int main() {
    int a = 5;
    int b = 3;
    std::cout << "Sum: " << a + b << std::endl;
    return 0;
}
ASum: 8
BSum: 53
CSum: 15
DSum: 2
Attempts:
2 left
💡 Hint
Remember that + adds numbers, not strings.
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of C++?
Which option best describes the main purpose of C++?
AA language for system programming and performance-critical applications
BA language mainly for web page styling
CA language only for database queries
DA language used exclusively for mobile app design
Attempts:
2 left
💡 Hint
Think about where speed and control over hardware matter.
Predict Output
advanced
2:00remaining
Output of C++ code with pointers
What is the output of this C++ program?
C++
#include <iostream>
int main() {
    int x = 10;
    int* p = &x;
    *p = 20;
    std::cout << x << std::endl;
    return 0;
}
A10
BCompilation error
C20
DAddress of x
Attempts:
2 left
💡 Hint
Changing value via pointer changes original variable.
🔧 Debug
advanced
1:30remaining
Identify the error in this C++ code
What error does this C++ code produce?
C++
#include <iostream>
int main() {
    int a = 5;
    int b = 0;
    std::cout << a / b << std::endl;
    return 0;
}
ANo error, outputs 0
BSyntax error: missing semicolon
CType error: incompatible types
DDivision by zero runtime error
Attempts:
2 left
💡 Hint
Dividing by zero is not allowed.
🚀 Application
expert
2:30remaining
What is the output of this C++ code using classes?
What is the output of this program?
C++
#include <iostream>
class Counter {
public:
    int count = 0;
    void increment() { count++; }
};
int main() {
    Counter c1, c2;
    c1.increment();
    c2.increment();
    c2.increment();
    std::cout << c1.count << " " << c2.count << std::endl;
    return 0;
}
A2 1
B1 2
C0 0
DCompilation error
Attempts:
2 left
💡 Hint
Each object has its own count variable.