banner

Pointer


     In C language, a pointer is a variable that points to or references a memory location in which data is stored. Each memory cell in the computer has an address which can be used to access its location.  A pointer variable points to a memory location. By making use of pointer, we can access and change the contents of the memory location.    

     A pointer is a variable which contains the address in memory of another variable. We can have a pointer to any variable type.

The unary or monadic operator & gives the ``address of a variable''.

The indirection or dereference operator * gives the ``contents of an object pointed to by a pointer''.

To declare a pointer to a variable do:

   int *pointer;

Example:-

int x = 1, y = 2;

int *ip;

ip = &x;

y = *ip;

x = ip;

*ip = 3;
                     
Example:-

/* A program to illustrate pointer declaration */

main()
{
int *ptr;
int sum;
sum=45;
ptr=∑
printf ("n sum variable value is %dn", sum);
printf ("n The 'ptr' pointer variable value is %d", ptr);
}