📘 1.
5 A Structure of a C++ Program
✅ 6 Theory Points
1. Header files first (#include <iostream>) supply libraries.
2. An optional using namespace std; avoids writing std::
repeatedly.
3. main() is the single entry point where execution begins.
4. Statements live inside curly braces {} that mark the function body.
5. Every C++ statement ends with a semicolon ;.
6. A return 0; (or simply return) signals successful termination.
🧩 Syntax (bare minimum)
#include<iostream>
int main() { // program starts here
// statements
return 0;
}
💻 Example with Comments
#include<iostream> // 1. include library for I/O
using namespace std; // 2. simplify cout / cin
int main() { // 3. start of main
cout << "Hello, C++ structure!"; // 4. print a line
return 0; // 5. end of program
}
🖥 Output
Hello, C++ structure!
📘 1.5 B Basic Input / Output (I/O)
✅ 6 Theory Points
1. <iostream> provides cin (input) and cout (output) objects.
2. Extraction operator >> pulls data into variables (input).
3. Insertion operator << sends data out of variables (output).
4. endl (or \n) adds a newline and flushes the buffer.
5. I/O uses the stream concept—data flows like water through pipes.
6. When mixing different data types, streaming handles automatic
formatting.
🧩 Syntax Essentials
// Output
cout << value1 << " text " << value2 << endl;
// Input
cin >> variable;
💻 Example with Comments
#include<iostream>
using namespace std;
int main() {
string name; // variable for input
cout << "Enter your name: "; // prompt user
cin >> name; // get input
cout << "Welcome, " << name << "!" << endl; // show output
return 0;
}
🖥 Output (example run)
Enter your name: Aryan
Welcome, Aryan!