C++ Programming Notes (हिंदी + English) – Complete

Comprehensive study material – click a topic below to jump

Topics of C++ Programming

1. Introduction to C++ / C++ का परिचय

English

What is C++? C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C language. It adds object-oriented programming (OOP) features to C. C++ supports procedural, object-oriented, and generic programming.

Key Features:

  • Object-oriented – classes, inheritance, polymorphism, encapsulation
  • Rich library (Standard Template Library – STL)
  • Low-level memory manipulation (pointers)
  • High performance and efficiency
  • Multi‑paradigm

हिंदी

C++ क्या है? C++ एक सामान्य प्रयोग की प्रोग्रामिंग भाषा है जिसे ब्योर्न स्ट्रॉस्ट्रुप ने C भाषा के विस्तार के रूप में बनाया था। इसमें ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग (OOP) की सुविधाएँ जोड़ी गई हैं। C++ प्रोसीजरल, OOP और जेनेरिक प्रोग्रामिंग को सपोर्ट करती है।

मुख्य विशेषताएँ:

  • ऑब्जेक्ट-ओरिएंटेड – क्लास, इन्हेरिटेंस, पॉलीमॉर्फिज्म, एनकैप्सुलेशन
  • समृद्ध लाइब्रेरी (STL)
  • लो-लेवल मेमोरी मैनिपुलेशन (पॉइंटर्स)
  • उच्च प्रदर्शन और दक्षता
  • बहु-प्रतिमान
// First C++ program
#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

Explanation: #include <iostream> includes input/output stream. using namespace std; allows use of standard names. cout outputs text.

व्याख्या: #include <iostream> इनपुट/आउटपुट स्ट्रीम लाइब्रेरी शामिल करता है। using namespace std; से हम स्टैंडर्ड नेमस्पेस का उपयोग कर सकते हैं। cout आउटपुट के लिए है।

↑ Back to Top

2. Basic Syntax / मूल वाक्यविन्यास

English

  • Semicolons (;): every statement ends with semicolon.
  • Comments: // single line, /* multi-line */.
  • Braces {}: group statements.
  • Case sensitive: main and Main are different.

हिंदी

  • सेमीकोलन (;): हर स्टेटमेंट के बाद सेमीकोलन जरूरी है।
  • कमेंट्स: // एक लाइन, /* एक से ज्यादा लाइनें */
  • ब्रैसेस {}: स्टेटमेंट्स के समूह के लिए।
  • केस सेंसिटिव: C++ छोटे-बड़े अक्षरों में फर्क करती है।
// Example
#include <iostream>
using namespace std;

int main() {
    int a = 10;   // semicolon
    int b = 20;
    int sum = a + b;
    cout << "Sum = " << sum << endl;
    return 0;
}
↑ Back to Top

3. Data Types / डेटा प्रकार

English

Primary: int, float, double, char, bool, void

Derived: arrays, pointers, references, functions

User-defined: classes, structures, unions, enums

हिंदी

मूल: int, float, double, char, bool, void

डिराइव्ड: ऐरे, पॉइंटर्स, रेफरेंसेस, फंक्शन

यूजर-डिफाइंड: क्लास, स्ट्रक्चर, यूनियन, एनम

#include <iostream>
using namespace std;

int main() {
    int age = 21;
    float price = 99.99;
    double pi = 3.1415926535;
    char grade = 'A';
    bool isPass = true;

    cout << "Age: " << age << endl;
    cout << "Price: " << price << endl;
    cout << "Pi: " << pi << endl;
    cout << "Grade: " << grade << endl;
    cout << "Pass: " << isPass << endl;
    return 0;
}
↑ Back to Top

4. Variables & Constants / चर और स्थिरांक

English

Variables: named memory locations. Declaration: data_type var_name;

Constants: values that cannot change. Use const keyword: const int DAYS = 7;

हिंदी

वेरिएबल: नाम दिया गया मेमोरी लोकेशन। डिक्लेरेशन: डेटा_टाइप वेरिएबल_नाम;

कॉन्स्टैंट्स: वैल्यू जो बदली नहीं जा सकती। const कीवर्ड का प्रयोग: const int DAYS = 7;

int a = 10;          // variable
const int B = 20;    // constant
a = 15;              // ok
// B = 25;           // error
↑ Back to Top

5. Input / Output / इनपुट / आउटपुट

English

cout for output, cin for input, endl for newline.

हिंदी

cout आउटपुट के लिए, cin इनपुट के लिए, endl नई लाइन के लिए।

#include <iostream>
using namespace std;

int main() {
    int age;
    string name;
    cout << "Enter name: ";
    cin >> name;
    cout << "Enter age: ";
    cin >> age;
    cout << "Hello " << name << ", age " << age << endl;
    return 0;
}
↑ Back to Top

6. Operators / ऑपरेटर

English

Arithmetic: +, -, *, /, %
Relational: ==, !=, <, >, <=, >=
Logical: &&, ||, !
Assignment: =, +=, -=, *=, /=, %=
Increment/Decrement: ++, --
Bitwise: &, |, ^, ~, <<, >>
Conditional: ? :

हिंदी

अरिथमेटिक: +, -, *, /, %
रिलेशनल: ==, !=, <, >, <=, >=
लॉजिकल: &&, ||, !
असाइनमेंट: =, +=, -=, *=, /=, %=
इन्क्रीमेंट/डिक्रीमेंट: ++, --
बिटवाइज: &, |, ^, ~, <<, >>
कंडीशनल: ? :

int a=10, b=3;
cout << a+b; // 13
cout << (a>b); // 1 (true)
a++; // a=11
↑ Back to Top

7. Control Structures / नियंत्रण संरचनाएँ

English

if, else if, else, switch.

हिंदी

if, else if, else, switch.

int num;
cin >> num;
if (num > 0) cout << "Positive";
else if (num == 0) cout << "Zero";
else cout << "Negative";

switch(day) {
    case 1: cout << "Mon"; break;
    case 2: cout << "Tue"; break;
    default: cout << "Other";
}
↑ Back to Top

8. Loops / लूप्स

English

for, while, do-while.

हिंदी

for, while, do-while.

for (int i=1; i<=5; i++) cout << i;
int j=1; while(j<=5) { cout << j; j++; }
int k=1; do { cout << k; k++; } while(k<=5);
↑ Back to Top

9. Arrays / ऐरे

English

Collection of same-type elements. Declaration: int arr[5];

हिंदी

एक ही टाइप के एलिमेंट्स का समूह। डिक्लेरेशन: int arr[5];

int arr[5] = {10,20,30,40,50};
for(int i=0; i<5; i++) cout << arr[i] << " ";
↑ Back to Top

10. Strings / स्ट्रिंग्स

English

Use #include <string>. C++ string class.

हिंदी

#include <string> का उपयोग करें। C++ string क्लास।

#include <string>
string s = "Hello";
cout << s.length() << s[0];
string t = "World";
string u = s + " " + t;
↑ Back to Top

11. Functions / फंक्शन

English

Function overloading, default arguments, pass by value/reference.

हिंदी

फंक्शन ओवरलोडिंग, डिफॉल्ट आर्ग्यूमेंट्स, पास बाय वैल्यू/रेफरेंस।

int add(int a, int b) { return a+b; }
double add(double a, double b) { return a+b; } // overload
void swap(int &x, int &y) { int t=x; x=y; y=t; } // reference
↑ Back to Top

12. Pointers / पॉइंटर्स

English

Pointer stores address of another variable. Use & to get address, * to dereference.

हिंदी

पॉइंटर दूसरे वेरिएबल का एड्रेस स्टोर करता है। एड्रेस के लिए &, वैल्यू के लिए *

int x = 10;
int *ptr = &x;
cout << *ptr; // 10
*ptr = 20;    // x becomes 20
↑ Back to Top

13. References / रेफरेंसेस

English

Reference is an alias to an existing variable. Must be initialized.

हिंदी

रेफरेंस किसी मौजूदा वेरिएबल का उपनाम होता है। इनिशियलाइज करना जरूरी है।

int a = 5;
int &ref = a; // ref is alias of a
ref = 10;     // a becomes 10
↑ Back to Top

14. Dynamic Memory / डायनामिक मेमोरी

English

Use new and delete for dynamic allocation.

हिंदी

डायनामिक एलोकेशन के लिए new और delete का उपयोग करें।

int *p = new int(5);
*p = 10;
delete p;

int *arr = new int[10];
arr[0] = 1;
delete[] arr;
↑ Back to Top

15. Classes & Objects / क्लास और ऑब्जेक्ट

English

Class is blueprint for objects. Access specifiers: public, private, protected.

हिंदी

क्लास ऑब्जेक्ट का खाका है। एक्सेस स्पेसिफायर: public, private, protected।

class Student {
private:
    string name;
    int age;
public:
    void setData(string n, int a) { name=n; age=a; }
    void display() { cout << name << " " << age; }
};

Student s;
s.setData("Raj",20);
s.display();
↑ Back to Top

16. Constructors & Destructors / कंस्ट्रक्टर और डिस्ट्रक्टर

English

Constructor called when object created. Destructor called when object destroyed. Can be overloaded. Copy constructor, this pointer.

हिंदी

कंस्ट्रक्टर ऑब्जेक्ट बनने पर कॉल होता है। डिस्ट्रक्टर ऑब्जेक्ट नष्ट होने पर कॉल होता है। इन्हें ओवरलोड किया जा सकता है। कॉपी कंस्ट्रक्टर, this पॉइंटर।

class Rectangle {
    int w,h;
public:
    Rectangle() { w=0; h=0; }                // default
    Rectangle(int a, int b) { w=a; h=b; }    // parameterized
    Rectangle(const Rectangle &r) { w=r.w; h=r.h; } // copy
    ~Rectangle() { cout << "destroyed"; }
};
↑ Back to Top

17. Inheritance / इन्हेरिटेंस

English

Deriving new classes from existing ones. Types: single, multiple, multilevel, hierarchical, hybrid.

हिंदी

मौजूदा क्लास से नई क्लास बनाना। प्रकार: single, multiple, multilevel, hierarchical, hybrid।

class Shape {
protected:
    int width, height;
public:
    void setDim(int w, int h) { width=w; height=h; }
};
class Rectangle : public Shape {
public:
    int area() { return width*height; }
};
↑ Back to Top

18. Polymorphism / पॉलीमॉर्फिज्म

English

Runtime polymorphism via virtual functions. Abstract classes (pure virtual).

हिंदी

रनटाइम पॉलीमॉर्फिज्म वर्चुअल फंक्शन के जरिए। एब्सट्रैक्ट क्लास (pure virtual)।

class Base {
public:
    virtual void show() { cout << "Base"; }
};
class Derived : public Base {
public:
    void show() override { cout << "Derived"; }
};
Base *b = new Derived();
b->show(); // Derived
↑ Back to Top

19. Operator Overloading / ऑपरेटर ओवरलोडिंग

English

Define custom behavior for operators (+, -, etc.) for user-defined types.

हिंदी

यूजर-डिफाइंड टाइप के लिए ऑपरेटरों का व्यवहार परिभाषित करना।

class Complex {
    int real, imag;
public:
    Complex operator+(const Complex &c) {
        Complex temp;
        temp.real = real + c.real;
        temp.imag = imag + c.imag;
        return temp;
    }
};
↑ Back to Top

20. Friend & Static Members / फ्रेंड और स्टैटिक मेंबर

English

Friend functions can access private members. Static members belong to class, not object.

हिंदी

फ्रेंड फंक्शन प्राइवेट मेंबर्स एक्सेस कर सकते हैं। स्टैटिक मेंबर क्लास के होते हैं, ऑब्जेक्ट के नहीं।

class A {
private:
    int x;
public:
    friend void show(A &a);
    static int count;
};
int A::count = 0;
void show(A &a) { cout << a.x; }
↑ Back to Top

21. Templates / टेम्पलेट्स

English

Function templates and class templates for generic programming.

हिंदी

फंक्शन टेम्पलेट और क्लास टेम्पलेट जेनेरिक प्रोग्रामिंग के लिए।

template <typename T>
T add(T a, T b) { return a+b; }

template <class T>
class Box {
    T data;
public:
    void set(T d) { data = d; }
    T get() { return data; }
};
↑ Back to Top

22. STL (Standard Template Library) / एसटीएल

English

Containers: vector, list, map, set. Algorithms: sort, find, etc. Iterators.

हिंदी

कंटेनर: vector, list, map, set। एल्गोरिदम: sort, find, आदि। इटरेटर।

#include <vector>
#include <algorithm>
using namespace std;

vector<int> v = {5,2,8,1};
sort(v.begin(), v.end());
for(int x : v) cout << x << " ";

map<string,int> m;
m["apple"] = 10;
cout << m["apple"];
↑ Back to Top

23. Exception Handling / अपवाद प्रबंधन

English

Use try, catch, throw to handle runtime errors.

हिंदी

रनटाइम एरर हैंडल करने के लिए try, catch, throw का उपयोग।

try {
    int age;
    cin >> age;
    if (age < 18) throw age;
    cout << "Welcome";
} catch(int e) {
    cout << "Underage: " << e;
}
↑ Back to Top

24. File Handling / फ़ाइल हैंडलिंग

English

Use fstream, ifstream, ofstream.

हिंदी

fstream, ifstream, ofstream का उपयोग करें।

#include <fstream>
ofstream out("file.txt");
out << "Hello";
out.close();

ifstream in("file.txt");
string line;
getline(in, line);
in.close();
↑ Back to Top

25. Modern C++ (C++11/14/17/20) / आधुनिक C++

English

  • auto keyword
  • Range-based for loop
  • Smart pointers (unique_ptr, shared_ptr)
  • Lambda expressions
  • nullptr
  • Move semantics (std::move)
  • Threading support

हिंदी

  • auto कीवर्ड
  • रेंज-बेस्ड for लूप
  • स्मार्ट पॉइंटर्स (unique_ptr, shared_ptr)
  • लैम्ब्डा एक्सप्रेशन
  • nullptr
  • मूव सेमेंटिक्स (std::move)
  • थ्रेडिंग सपोर्ट
auto i = 10;                    // type deduced
vector<int> v = {1,2,3};
for (auto x : v) cout << x;    // range-based

auto lambda = [](int a, int b) { return a+b; };
cout << lambda(5,3);

unique_ptr<int> p(new int(5)); // smart pointer
↑ Back to Top