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.
Satti said:
1 decade ago
Satish, p declared as a character pointer,so a is not a character type. so we can covert a type to p char type.
char *p;
int i=10;
p=(char*)i;// type casting is done.
char *p;
int i=10;
p=(char*)i;// type casting is done.
Arun said:
1 decade ago
VISHAL explanation is fine.
Kiran chowdary said:
1 decade ago
I agree with preeti, but can u tell me where we use this.
Jitendra jain said:
1 decade ago
I think about this qstn that
it is not well known form
i exicute that in my pc but result come this
but nobody explain me how it work??
it is not well known form
i exicute that in my pc but result come this
but nobody explain me how it work??
IRSHAD ALAM said:
1 decade ago
@ Preethi: Thnx for providing nice answer...
clear to understand.
clear to understand.
MOHD ILYAS DCET said:
1 decade ago
The above explanations are correct I would like to give an idea about another method of arrangement i.e 'Big-endian' here we can arrange 1234 as 3-4-1-2 or 2-1-4-3 in the memory addresses
Prabha said:
1 decade ago
Can any one please tel me how to do normalization ?
Nikita said:
1 decade ago
a=5.375 IS REPRESENTED AS '40 AC 00 00'. When stored in memory in case of little endian its stored as..
(eg.) 500 501 502 503
a = 00 00 AC 40
Now p=(char *)&a; means p will hold address of a and p is of char type so after typecasting it will hold 500 which hold 00, on incrementing it will print respective values.
(eg.) 500 501 502 503
a = 00 00 AC 40
Now p=(char *)&a; means p will hold address of a and p is of char type so after typecasting it will hold 500 which hold 00, on incrementing it will print respective values.
Santosh said:
1 decade ago
#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;
}
Please give me the description for how the above program is executing.
#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;
}
Please give me the description for how the above program is executing.
Muthulakshmi said:
1 decade ago
How will I understand the c program easily I feel the programs are very difficult. It is easy or not and please teach me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers