0% found this document useful (0 votes)
2 views2 pages

CPP Notes Module1

This document provides an overview of basic C++ syntax, including the structure of a standard program, variable declarations, and control flow mechanisms. It emphasizes the importance of explicitly declaring variable types and illustrates conditional logic with if-else statements, as well as iteration through for and while loops. Key data types covered include int, double, char, std::string, and bool.

Uploaded by

bs910772
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

CPP Notes Module1

This document provides an overview of basic C++ syntax, including the structure of a standard program, variable declarations, and control flow mechanisms. It emphasizes the importance of explicitly declaring variable types and illustrates conditional logic with if-else statements, as well as iteration through for and while loops. Key data types covered include int, double, char, std::string, and bool.

Uploaded by

bs910772
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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--;
}

You might also like