0% found this document useful (0 votes)
41 views3 pages

1.5 Notes

The document outlines the structure of a C++ program, emphasizing key components such as header files, the main function, and syntax rules. It also covers basic input and output operations using cin and cout, along with operators for data extraction and insertion. Examples illustrate the concepts, demonstrating how to prompt for user input and display output.

Uploaded by

ARYAN MOHADE
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)
41 views3 pages

1.5 Notes

The document outlines the structure of a C++ program, emphasizing key components such as header files, the main function, and syntax rules. It also covers basic input and output operations using cin and cout, along with operators for data extraction and insertion. Examples illustrate the concepts, demonstrating how to prompt for user input and display output.

Uploaded by

ARYAN MOHADE
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
You are on page 1/ 3

📘 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!

You might also like