C++ Important Topics - Exam-Oriented Notes
1. Class and Object
Class: User-defined data type. Blueprint jisme variables & functions hote hain.
Object: Class ka real-world instance.
Example:
class Student {
public:
int roll;
void display() {
cout << "Roll: " << roll;
}
};
2. Constructor and Destructor
Constructor: Class ka special function, object bante hi call hota hai.
Destructor: Object destroy hone par call hota hai.
Example:
class A {
public:
A() { cout << "Constructor"; }
~A() { cout << "Destructor"; }
};
3. Inheritance
One class inherits features of another.
Types: Single, Multiple, Multilevel, Hierarchical, Hybrid
Example:
class A {
public: void show() { cout << "Base"; }
};
class B : public A {
public: void display() { cout << "Derived"; }
};
C++ Important Topics - Exam-Oriented Notes
4. Function Overloading
Same function name, different arguments.
Example:
void sum(int a, int b);
void sum(float x, float y);
5. Operator Overloading
Redefine operators like +, -, etc.
Example:
class A {
int val;
public:
A(int x) { val = x; }
A operator+(A obj) {
return A(val + obj.val);
}
};
6. Friend Function
Function jo class ke private members ko access kar sakta hai.
Example:
class Box {
int length;
friend void display(Box b);
};
7. Encapsulation and Abstraction
Encapsulation: Data + functions ko ek unit mein rakhna (class).
Abstraction: Important details dikhana, baaki chhupana (use public interface).
8. Access Specifiers
Public: Accessible anywhere
Private: Class ke andar hi
C++ Important Topics - Exam-Oriented Notes
Protected: Class + derived class
9. Arrays in Class
Class ke andar array banana
Example:
class Marks {
int m[5];
};
10. Pointers with Objects
Object ko pointer se access karna
Example:
Student *ptr = &s1;
ptr->display();