Thursday 4 August 2016

Pointer Arithmetic

Pointer Arithmetic


#include<stdio.h>
void main()
{
                char c = 'x', *pc;
                int i = 11, *pi;
                float f = 35.6, *pf;
                pc = &c;
                pi = &i;
                pf = &f;
                printf("\nValue of pc = Address of c = %p ", pc);
                printf("\nValue of pi = Address of i = %p ", pi);
                printf("\nValue of pf = Address of f = %p ", pf);

                pc++;
                pi++;
                pf++;

                printf("\nNow Value of pc = %p", pc);
                printf("\nNow Value of pi = %p", pi);
                printf("\nNow Value of pf = %p", pf);
}

Output:
Value of pc  =     Address of c       = 0028FF47
Value of pi   =     Address of i        = 0028FF3C
Value of pf   =    Address of f       = 0028FF34
Now Value of pc = 0028FF48
Now Value of pi = 0028FF40
Now Value of pf = 0028FF38

No comments:

Post a Comment