Unit IV Pointers and Polymorphism
Unit IV Pointers and Polymorphism
- Pointer Operator: The '*' operator is used to access the value at the address the pointer points to.
- Address Operator: The '&' operator is used to get the address of a variable.
- Pointer Arithmetic:
- Increment/Decrement: ptr++ or ptr-- moves the pointer to the next/previous memory location.
Example:
int a = 10;
Pointers can also point to objects. This allows dynamic memory allocation and the use of 'this' and
Example:
Base *bptr;
Derived d;
Polymorphism means "many forms." It allows a single function or operator to behave differently
Types:
1. Compile-Time Polymorphism:
2. Run-Time Polymorphism:
- Constructor Overloading:
- Operator Overloading:
Example:
class Complex {
public:
Complex res;
return res;
};
4.5 Run-Time Polymorphism
- Virtual Function:
Rules:
Example:
class Base {
public:
};
public:
}
};