1.
Function Overloading in C++:
Function overloading allows multiple functions with the same name but different parameters.
Example:
int add(int a, int b);
float add(float a, float b);
2. Polymorphism and Its Types:
Polymorphism means "many forms".
Types:
- Compile-time (Function/Operator Overloading)
- Runtime (Virtual functions & Inheritance)
3. Difference: Function Overloading vs Overriding
| Feature | Overloading | Overriding |
|-----------------|----------------------------------|-------------------------------------|
| Class Involved | Same class | Base and Derived classes |
| Binding Time | Compile-time | Runtime |
| Signature | Different | Same |
4. Function Overloading Example (Area Calculation):
float area(float radius);
int area(int length, int breadth);
5. Friend Function:
A function that can access private members of a class.
Merits: Access to private data, operator overloading support.
Demerits: Breaks encapsulation, increases coupling.
6. Pointer in C++:
A variable that stores the address of another variable.
Advantages: Efficient memory usage, dynamic memory allocation, array handling.
7. Stream in C++:
A stream is a flow of data.
Types:
- Input: cin, ifstream
- Output: cout, ofstream, cerr, clog
8. File I/O in C++:
Classes: ifstream, ofstream, fstream
Functions: open(), close(), is_open(), getline(), read(), write()
Example:
ofstream file("data.txt"); file << "Hello";
ifstream file("data.txt"); getline(file, line);