0
0
C++programming~5 mins

Structure of a C++ program - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
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:<br>
#include <iostream>
using namespace std;

int main() {
  cout << "Hello, world!" << endl;
  return 0;
}
1. #include <iostream> - includes input/output library.<br>2. using namespace std; - allows using standard names.<br>3. int main() - main function where execution starts.<br>4. cout << "Hello, world!" << endl; - prints text.<br>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()
What does #include <iostream> do?
ADefines the main function
BIncludes input/output functions
CStarts the program
DDeclares variables
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
What does return 0; mean in main()?
AProgram ended successfully
BProgram has an error
CStart the program
DDeclare a variable
Which line prints text to the screen in this code?<br>
int main() {
  cout << "Hi!" << endl;
  return 0;
}
Areturn 0;
Bint main()
Ccout << "Hi!" << endl;
Dendl;
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.