BLOG DETAILS

More about Pointers in C Language

  • By Suresh Kulahry
  • |
  • January 01, 2019

The pointer is a special type of variable that is used to hold or store memory location (address) rather than value. Pointer can have any name that is legal for other variables and it is declared in the same fashion as other variables but is always denoted by an asterisk (*) operator.

FEATURES OF POINTER:

  1. It is a powerful feature of ‘C language’.
  2. Execution time with pointer is faster because data is manipulated with the address, i.e. direct access to memory location.
  3. Pointers are used for file handling.
  4. Pointers are used to allocate memory dynamically.
  5. It stores the address, not values.
  6. Pointer allows carry whole array to the function.
  7. Pointers will help in returning more than one value from the function.
  8. It allows indirect access of data.

POINTER DECLARATION:
                                            The declaration of the pointer variable is similar to a normal variable declaration but preceding with an asterisk (*) symbol.

Syntax:
                Data_Type *Variable_Name;
Example:
                 int *ptr;
Here type of variable ptr is ‘pointer to int’ or (int *), or we can say that the base type of ptr is int.

INITIALIZATION OF POINTER VARIABLE:

Global and local static pointers are automatically initialized to NULL but when we declare an automatic pointer variable it contains garbage value i.e. it may be pointing anywhere in the memory. So, we should always assign an address before using it in the program.

Example:
                int *ptr;
                int num=26;
                ptr=#

Pointer variable of any type always occupy 2 bytes (in 16-bit compiler) and 4 bytes (in 32-bit compiler) in memory because pointer variable is used for storing address, not value.