C++ Basics Quiz
40 in-depth questions covering C++ fundamentals, program structure, input/output operations, comments, compilation process, and exit codes — with 10 code examples to solidify understanding.
Question 1
When developing a C++ application that needs to read user input from the console and display formatted output, which header file must be included to access the standard I/O streams?
Question 2
In a C++ program that processes command-line arguments and returns different exit codes based on success or failure conditions, what is the correct signature for the main function?
Question 3
During the C++ compilation process, what happens when the preprocessor encounters an #include directive for a standard library header like <iostream>?
Question 4
When writing a C++ program that needs to handle both successful execution and error conditions, what are the conventional exit code values that should be returned from main?
Question 5
In a cross-platform C++ application that must work on both Windows and Unix-like systems, what namespace qualification is typically used with standard library components?
Question 6
Consider this C++ code that attempts to read an integer from console input and display it. What will happen when this program runs and the user enters '42' followed by Enter?
#include <iostream>
int main() {
int number;
std::cin >> number;
std::cout << "You entered: " << number << std::endl;
return 0;
}Question 7
When compiling a multi-file C++ project with separate header and implementation files, what is the typical sequence of commands using g++ compiler?
Question 8
In a C++ program that includes both single-line and multi-line comments, what happens to these comments during the compilation process?
Question 9
When developing a C++ library that will be used by other programs, what considerations should be made regarding the main function and program structure?
Question 10
In a complex C++ build system where multiple source files include the same standard headers, how does the preprocessor prevent duplicate symbol definitions?
