main()
{
int i=257;
float a=3.14;
char *ii,*aa;
ii=(char*)%26amp;i; //what (char*) is doing here
aa=(char*)%26amp;a;
printf("address in ii=%u",ii);
printf("address in aa=%u",aa);
printf("vallue of i=%d",*ii);
printf("vallue of a=%f",*aa);
}
Explain the output of the c prog?
What is (char*) doing there? Simple! It converts int to char for ii and float to char for aa. The compiler doesn't automatically convert int to char or float! (because int is larger then char, and by converting it you loose data, same for float..).
And now refering to the output... It depends on what system this source is compiled, and nevertheless on the compiler you are using! The problem consists in converting an int to a char, and it depends on the compiler how many bytes are allocated when declaring an int! (same for converting float to char)
Reply:(char*) will convert integer variable into character. So value assigned to ii and aa will be behaved as a character variable for rest of the programme.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment