C++ Quick Notes — Module 1
Syntax, Variables, & Control Flow
1. Basic Structure & Compilation
Every standard C++ program follows a structured baseline template execution. The entry point of any C++
execution is the main() function.
#include <iostream> // Preprocessor directive for Input/Output streams
int main() {
// This is a single-line comment
std::cout << "Hello, World!" << std::endl;
return 0; // Signals execution success (0) to the OS
}
2. Strongly Typed Variable Declarations
C++ requires all variables to have an explicitly declared data type before compilation. Common fundamental
types include:
• int : Integrated integers (e.g., 42, -7)
• double : Double-precision floating point numbers (e.g., 3.14159)
• char : A single 8-bit character enclosed in single quotes (e.g., 'A')
• std::string : Sequence of characters wrapped in double quotes (requires #include <string> )
• bool : Boolean conditional logic state ( true or false )
int age = 21;
double basePrice = 99.99;
char sequenceGrade = 'A';
std::string userProfile = "Alice";
bool dynamicState = true;
3. Conditional Logic & Control Flow Loops
Control flow structure dictates program execution branching behavior dynamically.
Conditional Branching (If-Else)
if (age >= 18) {
std::cout << "Access Granted: Adult Standard";
} else {
std::cout << "Access Denied: Restricted Minor";
}
Determined Iteration (For Loops)
Utilized when the total exact bounding runtime bounds are pre-determined:
for (int index = 0; index < 5; index++) {
std::cout << index << " "; // Outputs sequentially: 0 1 2 3 4
}
Conditional Iteration (While Loops)
Repeats execution dynamically as long as the state evaluation remains true:
int executionEnergy = 3;
while (executionEnergy > 0) {
std::cout << "Executing Process Thread...
";
executionEnergy--;
}