0
0
C++programming~5 mins

main function and program entry in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the main function in a C++ program?
The main function is the starting point of a C++ program. When you run the program, the computer begins executing code from main.
Click to reveal answer
beginner
What does the return value of main represent?
The return value of main tells the operating system if the program ended successfully. Returning 0 usually means success, while other values can indicate errors.
Click to reveal answer
intermediate
Which signature is the most common for the main function?
The most common signature is int main() or int main(int argc, char* argv[]). The first has no parameters; the second can receive command-line arguments.
Click to reveal answer
intermediate
What happens if you omit the return statement in main?
In modern C++, if you omit return in main, the compiler assumes return 0; automatically, meaning successful program end.
Click to reveal answer
beginner
Why is the main function special compared to other functions?
Because the operating system looks for main to start running your program. Other functions are called from main or each other, but main is the entry point.
Click to reveal answer
What is the return type of the main function in C++?
Aint
Bvoid
Cfloat
Dchar
What does return 0; in main usually mean?
AProgram is still running
BProgram crashed
CProgram ended successfully
DProgram needs input
Which of these is a valid main function signature?
Afloat main(int)
Bint main()
Cvoid main()
Dchar main()
What happens if you omit return in main in modern C++?
AThe program never ends
BThe program crashes
CThe program returns garbage
DThe compiler assumes <code>return 0;</code>
What is the role of the main function?
AProgram entry point
BFunction to print text
CFunction to read input
DFunction to declare variables
Explain the role of the main function in a C++ program and what its return value means.
Think about what happens when you run a program.
You got /4 concepts.
    Describe the common signatures of the main function and why you might use parameters in it.
    Consider how programs can get input when they start.
    You got /3 concepts.