Pointer in C

 

Pointers are variables that contains memory addresses as their values.The & or address operator, is a unary operator that returns the address of its operand.

 

For example, assuming the declarations

          int y=5;

         int *yptr;

the statement

            yptr=&y;

   assigns the address of the variable y to pointer variable yptr. Variable yptr is then said to “point to’ y.This shows a schematic representation of memory after the preceding assignment is executed.

The *operator, commonly referred to as the indirection operator or dereferencing operator, returns the value of the object to which its operand(i.e, a pointer)points. For example, the statement

       Printf(“%d”,*yptr);

Prints the value of variable y, namely 5. Using * in this manner is called dereferencing a pointer.

#include<stdio.h>

#include<conio.h>

int main()

    {

       int aa;  /* aa is an integer*/

       int *aaptr;   /*aaptr is a pointer to an integer*/

       clrscr();

       aa=75;

       aaptr=&aa;  /* aaptr set to address of aa*/

       printf("The address of aa is %p""\n The value of aaptr is %p",&aa,aaptr);

       printf("\n\nThe value of aa is %d""\n The value of *aaptr is %d",aa,*aaptr);

       printf("\n\n Showing that * and & are inverses of""each other.\n&*aaptr=%p""\n*&aaptr=%p\n",&*aaptr,*&aaptr);

                 getch();

                 return 0;

}

Output....

Pointer in C