Challenge - 5 Problems
C++ Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple C++ program with main function
What is the output of this C++ program?
C++
#include <iostream> int main() { std::cout << "Hello, C++!" << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Look carefully at the exact text inside the quotes and the capitalization.
✗ Incorrect
The program prints exactly "Hello, C++!" followed by a newline. The std::endl inserts a newline and flushes the output.
❓ Predict Output
intermediate2:00remaining
Value of variable after execution
What is the value of variable x after running this program?
C++
#include <iostream> int main() { int x = 5; x = x + 10; std::cout << x << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Look at how x is updated after initialization.
✗ Incorrect
x starts at 5, then 10 is added, so x becomes 15.
❓ Predict Output
advanced2:00remaining
Output of program with missing return in main
What is the output or result of this C++ program?
C++
#include <iostream> int main() { std::cout << "Test"; }
Attempts:
2 left
💡 Hint
In modern C++, main can omit return 0; and still run correctly.
✗ Incorrect
Since C++11, main returns 0 implicitly if no return statement is present. The program prints "Test".
❓ Predict Output
advanced2:00remaining
Output of program with multiple functions
What is the output of this C++ program?
C++
#include <iostream> void greet() { std::cout << "Hi"; } int main() { greet(); std::cout << " there!" << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Check the exact characters printed and the effect of std::endl.
✗ Incorrect
The greet function prints "Hi" without newline. main prints " there!" and then std::endl adds a newline. So output is "Hi there!\n".
🧠 Conceptual
expert2:00remaining
Order of sections in a C++ program
Which of the following shows the correct order of sections in a typical C++ program?
Attempts:
2 left
💡 Hint
Think about what the compiler needs first to understand the program.
✗ Incorrect
First, #include directives bring in libraries. Then namespace declarations set scope. Then functions are declared/defined. Finally, main function runs the program.