Let's start with the foundation. Every C++ program follows a basic structure that you need to understand cold before anything else makes sense.
#include <iostream> // Preprocessor directive - includes input/output library
using namespace std; // Lets us use 'cout' instead of 'std::cout'
int main() { // Entry point - execution ALWAYS starts here
cout << "Hello, World!" << endl; // Statement 1
return 0; // Tells OS the program ended successfully
}
1. Preprocessor Directives (#include)
# are processed before compilation, by the preprocessor.#include <iostream> pulls in the Standard Input/Output stream library so you can use cout, cin, etc.<string>, <vector>, <cmath>.2. Namespaces (using namespace std;)
cout, cin, string, etc.) live inside a namespace called std.std::cout every time.3. The main() function
main() function.main() first when you run the program.int: it returns a status code to the operating system.
return 0; → successreturn 1; (or any non-zero) → some error occurred4. Statements & Semicolons
;.