C Programming - Floating Point Issues - Discussion
Discussion Forum : Floating Point Issues - General Questions (Q.No. 3)
3.
If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?
#include<stdio.h>
#include<math.h>
int main()
{
float a=5.375;
char *p;
int i;
p = (char*)&a;
for(i=0; i<=3; i++)
printf("%02x\n", (unsigned char)p[i]);
return 0;
}
Discussion:
117 comments Page 5 of 12.
Sudhir said:
1 decade ago
Here what is mean by printf("%02x\n", (unsigned char)p[i]); statement, please explain me.
Shwetha said:
1 decade ago
If we go according to preethi the answer should be 00 00 CA 04
but the answer given is 00 00 AC 40
but the answer given is 00 00 AC 40
Vinay said:
1 decade ago
Vishal pandey is correct but how you can normalised the last address p[3]=00000000 10000000 as 40.
Raj said:
1 decade ago
In little endian, lower order bytes will be stored in lower addresses. But how this is the answer?
Sirisha said:
1 decade ago
p=(char *)&a;
satish i thik (char*)this is for type casting as
a is float and p is char
satish i thik (char*)this is for type casting as
a is float and p is char
Hajmal deen said:
1 decade ago
Preethi is correct, but I can't understand, so explain clearly. Please do the needful.
Anand said:
1 decade ago
Hexadecimal conversion of the variable in the code. That's it nothing more than that.
Sathish said:
1 decade ago
Hi, i have a doubt
in the statement
p=(char *)&a;
why we are used (char *) here
in the statement
p=(char *)&a;
why we are used (char *) here
Swathi said:
1 decade ago
Can you explain the program for me once again and also the execution part also.
Vinoth said:
1 decade ago
I am also same doubt as Shweta. Why we take every two bits rather than 1 bit.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers