Thursday, 4 August 2016

Pointers and address basics

Pointers and Address


#include<stdio.h>
void main()
{
                 int a = 10;
                float b = 35.6;
                int *p1;
                float *p2;
                p1 = &a;
                p2 = &b;
                printf("\nAddress of a = %p ", &a);
                printf("\nAddress of b = %p ", &b);

                printf("\nValue of a = %d %d %d", a, *p1, *(&a));
                printf("\nValue of b = %.1f %.1f %.1f", b, *p2, *(&b));

                printf("\nValue of p1 = Address of a = %p ", p1);
                printf("\nValue of p2 = Address of b = %p ", p2);

                printf("\nAddress of p1 = %p ", &p1);
                printf("\nAddress of p2 = %p ", &p2);
}

Output:
Address of a = 0028FF44
Address of b = 0028FF40
Value of a = 10    10   10
Value of b = 35.6   35.6   35.6
Value of p1 = Address of a = 0028FF44
Value of p2 = Address of b = 0028FF40
Address of p1 = 0028FF3C
Address of p2 = 0028FF38

No comments:

Post a Comment