What is the starting point of execution in a C++ program?
The main() function is the starting point where the program begins execution.
Click to reveal answer
beginner
What is the purpose of #include directives in a C++ program?
They tell the compiler to include the contents of a file, usually a library, so you can use its functions and features.
Click to reveal answer
beginner
What does using namespace std; do in a C++ program?
It allows you to use names from the std namespace (like cout and endl) without writing std:: before them.
Click to reveal answer
beginner
Identify the parts of this simple C++ program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}
1. #include <iostream> - includes input/output library. 2. using namespace std; - allows using standard names. 3. int main() - main function where execution starts. 4. cout << "Hello, world!" << endl; - prints text. 5. return 0; - ends the program successfully.
Click to reveal answer
beginner
Why do we write return 0; at the end of main()?
It tells the operating system that the program finished successfully. Zero usually means no errors.
Click to reveal answer
Which function is the entry point of every C++ program?
Amain()
Bstart()
Cinit()
Dbegin()
✗ Incorrect
The main() function is where execution starts in C++.
What does #include <iostream> do?
ADefines the main function
BIncludes input/output functions
CStarts the program
DDeclares variables
✗ Incorrect
It includes the standard input/output library so you can use cout and cin.
What is the purpose of using namespace std;?
ATo declare variables
BTo include the standard library
CTo start the program
DTo avoid writing <code>std::</code> before standard names
✗ Incorrect
It lets you use standard library names without the std:: prefix.
What does return 0; mean in main()?
AProgram ended successfully
BProgram has an error
CStart the program
DDeclare a variable
✗ Incorrect
Returning zero signals successful program completion to the operating system.
Which line prints text to the screen in this code?
int main() {
cout << "Hi!" << endl;
return 0;
}
Areturn 0;
Bint main()
Ccout << "Hi!" << endl;
Dendl;
✗ Incorrect
The cout line sends text to the screen.
Describe the basic structure of a simple C++ program and explain the role of each part.
Think about what each line does from top to bottom.
You got /5 concepts.
Why is the main() function important in C++? What happens if it is missing?
Consider what the computer looks for to start running your code.
You got /4 concepts.
Practice
(1/5)
1. Which function does a C++ program start executing from?
easy
A. init()
B. start()
C. begin()
D. main()
Solution
Step 1: Understand program entry point
In C++, the program always starts running from the main() function.
Step 2: Identify correct function name
Other function names like start(), init(), or begin() are not recognized as entry points.
Final Answer:
main() -> Option D
Quick Check:
Program starts at main() [OK]
Hint: Remember: C++ always starts at main() function [OK]
Common Mistakes:
Thinking start() or init() is the entry point
Confusing main with other function names
Assuming program runs from top to bottom without main
2. Which of the following is the correct way to include the input/output library in a C++ program?
easy
A. include <iostream>
B. #include <iostream>
C. #include iostream
D. iostream
Solution
Step 1: Recognize correct include syntax
The correct syntax to include a library is #include <library> with a hash and angle brackets.
Step 2: Check each option
#include <iostream> uses #include <iostream> which is correct. Others miss the hash or angle brackets or use invalid tags.
Final Answer:
#include <iostream> -> Option B
Quick Check:
#include <iostream> is correct [OK]
Hint: Use #include with angle brackets for libraries [OK]
Common Mistakes:
Omitting the # symbol
Not using angle brackets around library name
Using incorrect tags like <include>
3. What will be the output of this C++ program?
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
medium
A. Hello, World!
B. cout << Hello, World!
C. Hello World
D. Error: missing semicolon
Solution
Step 1: Analyze the output statement
The program uses cout to print the string "Hello, World!" followed by a newline.
Step 2: Confirm syntax correctness
All syntax is correct, so the output will be exactly the string printed.
Final Answer:
Hello, World! -> Option A
Quick Check:
cout prints "Hello, World!" [OK]
Hint: cout prints exactly what is inside quotes [OK]
Common Mistakes:
Ignoring the comma and exclamation mark
Confusing cout syntax with printf
Assuming missing semicolon error
4. Identify the error in this C++ program:
#include <iostream>
using namespace std;
int main()
cout << "Hello" << endl;
return 0;
}
medium
A. Missing semicolon after main()
B. Missing #include directive
C. Missing curly braces { } for main function
D. Incorrect return type for main
Solution
Step 1: Check main function syntax
The main function must have curly braces { } to group its code block.
Step 2: Identify missing braces
The code lacks opening { after main() and closing } at the end, causing syntax error.
Final Answer:
Missing curly braces { } for main function -> Option C
Quick Check:
Main needs { } to group code [OK]
Hint: Always use { } to group main function code [OK]
Common Mistakes:
Thinking semicolon needed after main()
Ignoring missing braces error
Assuming #include is missing
5. You want to write a C++ program that prints "Welcome!" and then ends. Which of these is the correct minimal structure?
hard
A. #include <iostream>
using namespace std;
int main() {
cout << "Welcome!" << endl;
return 0;
}
B. int main() {
cout << "Welcome!" << endl;
}
C. #include <iostream>
int main() {
print("Welcome!");
return 0;
}
D. #include <iostream>
using namespace std;
void main() {
cout << "Welcome!" << endl;
}
Solution
Step 1: Check for required includes and namespace
To use cout, #include <iostream> and using namespace std; are needed.
Step 2: Verify main function signature and body
Main must return int and have curly braces. #include <iostream>
using namespace std;
int main() {
cout << "Welcome!" << endl;
return 0;
} meets all requirements.
Final Answer:
Option A is the correct minimal structure -> Option A
Quick Check:
Include iostream + main() with return int [OK]
Hint: Include iostream and use int main() with braces [OK]
Common Mistakes:
Using void main() instead of int main()
Omitting #include <iostream>
Using print() instead of cout
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.