#include<stdio.h>
int main()
{
int i = 5;
float a = 3.14;
char*ii,*aa;
ii = (char*)&i;
aa = (char*)&a;
printf("address contained in ii=%u\n",ii);
printf("address contained in aa=%u\n",aa);
printf("value at address contained in ii=%d\n",*ii);
printf("value at address contained in aa= %d\n",*aa);
return(0);
}
/*the output for the following program was
address contained in ii=65524
address contained in aa=65520
value at address contained in ii=5
value at address contained in aa=-61*/
What is the meaning of ii = (char*) &i and aa = (char*) &a also why does the compiler print value at address in ii to be correct and that in aa to be wrong? If you take any other value of i, say 327, then the value at address contained in ii will turn out to be something else. Can someone please explain it to me? I am not able to get a proper explanation from the book where the code is written.
Program source: understanding pointers in c. Author : yashvant kanetkar,4th edition.