C++ Notes for Class 11 (Detailed with Examples)
1. Introduction to C++
C++ is a general-purpose programming language created by Bjarne Stroustrup. It is an extension of the C
language and supports object-oriented programming. It is widely used for system/software development.
2. Structure of a C++ Program
Example:
#include<iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
Explanation:
- #include<iostream>: Preprocessor directive to include input-output stream.
- using namespace std: Allows direct use of std like cout, cin.
- int main(): Starting point of the program.
- cout: Prints output to the screen.
3. Data Types in C++
Basic data types: int, float, char, bool, double
Example:
int age = 16;
float weight = 55.5;
char grade = 'A';
bool isPass = true;
4. Variables and Constants
C++ Notes for Class 11 (Detailed with Examples)
Variables: Containers to store data.
Constants: Fixed values declared using 'const'.
Example:
int x = 5;
const float PI = 3.14;
5. Input and Output
cin and cout are used for input/output.
Example:
int num;
cin >> num; // takes input
cout << num; // prints output
6. Operators in C++
Types of Operators:
- Arithmetic (+, -, *, /, %)
- Relational (==, !=, >, <)
- Logical (&&, ||, !)
- Assignment (=, +=, -=)
Example:
int a = 10, b = 5;
cout << (a > b && b < 10); // returns true (1)
7. Conditional Statements
if, else if, else are used for decision making.
Example:
C++ Notes for Class 11 (Detailed with Examples)
int marks = 85;
if (marks >= 90)
cout << "Excellent";
else if (marks >= 60)
cout << "Good";
else
cout << "Try Harder";
8. Loops in C++
Loops: Used for repeating tasks.
Types:
- for loop
- while loop
- do-while loop
Example (for loop):
for (int i = 1; i <= 5; i++) {
cout << i;
9. Arrays
Array: Collection of elements of the same type.
Example:
int marks[5] = {90, 85, 76, 80, 95};
cout << marks[0]; // prints 90
10. Functions
Function: A block of code that performs a specific task.
C++ Notes for Class 11 (Detailed with Examples)
Example:
int add(int a, int b) {
return a + b;
int main() {
cout << add(4, 5); // prints 9