0

Hi all!
Please somebody explain me how this snippet is working!!

main()
{
float a 4.379;
char*p;
int i;
p=(char*)&a;
for(i=1;i<=3;i++)
printf("%02X",(unsigned char)p[i]);
}
4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Gaiety
0

Hi all!
Please somebody explain me how this snippet is working!!

main()
{
float a 4.379;
char*p;
int i;
p=(char*)&a;
for(i=1;i<=3;i++)
printf("%02X",(unsigned char)p[i]);
}

The code simply assigns the address of "a" to the character pointer "p" and then proceeds to check the value of the four bytes at address p[0], p[1],p[2], and p[3]...

Edited by gerard4143: n/a

0

Well it looks like that's what it's supposed to do.
It should print the hex representation of the floating point number 4.379.

But I don't see how it will compile and it will only print 3 of the 4 hex bytes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.