Pointers and Addresses in C

Posted by Mohit on Stack Overflow See other posts from Stack Overflow or by Mohit
Published on 2010-06-03T07:03:13Z Indexed on 2010/06/03 7:04 UTC
Read the original article Hit count: 204

Filed under:
|
|
#include "stdio.h"  
main()  
{  
int i=3,*x;  
float j=1.5,*y;  
char k='c',*z;  

x=&i;  
y=&j;  
z=&k;  

printf("\nAddress of x= %u",x);  
printf("\nAddress of y= %u",y);  
printf("\nAddress of z= %u",z);  

x++;  
y++;y++;y++;y++;  
z++;  

printf("\nNew Address of x= %u",x);  
printf("\nNew Address of y= %u",y);  
printf("\nNew Address of z= %u",z);  

printf("\nNew Value of i= %d",i);  
printf("\nNew Value of j= %f",j);  
printf("\nNew Value of k= %c\n",k);  
}  

Output:

Address of x= 3219901868
Address of y= 3219901860
Address of z= 3219901875
New Address of x= 3219901872
New Address of y= 3219901876
New Address of z= 3219901876
New Value of i= 3
New Value of j= 1.500000
New Value of k= c

The new address of variable y and z are same. How can two variables have same address and et have different values? Note: I used gcc compiler on Ubuntu 9.04

© Stack Overflow or respective owner

Related posts about c

    Related posts about programming-languages