0
0
C++programming~20 mins

Structure of a C++ program - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
C++ Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
AHello C++!
BHello, C++!
Chello, C++!
DCompilation error
Attempts:
2 left
💡 Hint
Look carefully at the exact text inside the quotes and the capitalization.
Predict Output
intermediate
2: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;
}
A15
B10
C5
DCompilation error
Attempts:
2 left
💡 Hint
Look at how x is updated after initialization.
Predict Output
advanced
2: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";
}
ATest
BCompilation error: missing return statement
CNo output
DRuntime error
Attempts:
2 left
💡 Hint
In modern C++, main can omit return 0; and still run correctly.
Predict Output
advanced
2: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;
}
ACompilation error
B
Hi there
C
Hi there!
D!ereht iH
Attempts:
2 left
💡 Hint
Check the exact characters printed and the effect of std::endl.
🧠 Conceptual
expert
2:00remaining
Order of sections in a C++ program
Which of the following shows the correct order of sections in a typical C++ program?
A1, 3, 2, 4
B3, 1, 2, 4
C2, 1, 3, 4
D1, 2, 3, 4
Attempts:
2 left
💡 Hint
Think about what the compiler needs first to understand the program.