Challenge - 5 Problems
C++ Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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; }
Attempts:
2 left
💡 Hint
Remember that + adds numbers, not strings.
✗ Incorrect
The program adds integers 5 and 3, resulting in 8.
🧠 Conceptual
intermediate1:30remaining
What is the main purpose of C++?
Which option best describes the main purpose of C++?
Attempts:
2 left
💡 Hint
Think about where speed and control over hardware matter.
✗ Incorrect
C++ is widely used for system software, games, and applications needing high performance.
❓ Predict Output
advanced2: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; }
Attempts:
2 left
💡 Hint
Changing value via pointer changes original variable.
✗ Incorrect
Pointer p points to x, so *p = 20 changes x to 20.
🔧 Debug
advanced1: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; }
Attempts:
2 left
💡 Hint
Dividing by zero is not allowed.
✗ Incorrect
Dividing an integer by zero causes a runtime error or crash.
🚀 Application
expert2: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; }
Attempts:
2 left
💡 Hint
Each object has its own count variable.
✗ Incorrect
c1 increments once, c2 increments twice, so output is '1 2'.