c - What is wrong with the fourth character of int variable? -
my machine 32-bit pc running centos system,and used gcc compile c codes. , int variable occupy 4 bytes.so wrote codes this...
#include "stdio.h" int main(){ int a=1; printf("%c",*(&a+1)+65); printf("%c",*(&a+2)+65); printf("%c",*(&a+3)+65); }
i thinking this: pc in 32-bit variable shoule stored in memory this:
&a 00000001 &a+1 00000000 &a+2 00000000 &a+3 00000000
so think answer should :aaa
real got :qa(the last 1 didn't print out.)
feel puzzled result. , what's more ,if digestion last 2 printf.which is:
#include "stdio.h" int main(){ int a=1; printf("%c",*(&a+1)+65); }
then got want:a
wrong codes or what;s real wrong thinking variable storing in memory...please me out of stuff,thanks.
here, &a
of type int*
, &a+1
points next int (4 bytes after). need convert &a
char*
before : ((char *) &a) + 1
Comments
Post a Comment