Q6. Explain the concept of a pointer and its purpose.
Ans. A pointer is a variable that holds a memory address. This address is usually the location of another variable in memory. If one variable contains the address of another variable, the first variable is said to pint to the second.
If a variable is going to hold a pointer, it must b declared as such. A pointer declaration consists of a base type, an * (asterisk), and the variable name. The general form of declaring a pointer variable is
where type is any valid C++ type and ptr is the name of the pointer variables.
declares a pointer to character.
The base type of the pointer defines what type of variables the pointer can point to. Technically, any type of pointer can point anywhere in memory. However, all pointer arithmetic is done relative to its base type so it is important to declare the pointer correctly.