posted by surbhi just now
main()
{
float a = 5.375;
char *p;
int i;
p=(char*)&a;
for(i=0;i<=3;i++)
printf("%02x",(unsigned char) p[i]);
}

how is the output of this program is ::

0000ac40

please let me know y this output has come

Answers were Sorted based on User's Feedback



posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0..

Answer / sandeep gupta

A very interesting question where u need knowledge of
Computer architecture also.... :) :) :) :)
The floating point(FP) no. are stored differently in memory
as: mantissa × 2^exponent [M× 2^E]. M is 23 bit long and E
is 8 bit. 1 bit is for sign of number. The format is :
SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM
Now binary of 5.375 is 101.011 which can be written in
normalized form(which has single 1 before decimal point) as
1.01011 × 2^2. This 1 and point(.) is always neglected while
storing the no. in registers. so mantissa is 01011 or
010110000000000000000000 × 2^E where E is 8 bit(0 to 255).
The actual value of the exponent is calculated by
subtracting 127 from the stored value (0 to 255) giving a
range of –127 to +128.
So here we need E=2 which we can get from 129(129-127=2)
whose binary is: 10000001.
Now above format becomes:
0100 0000 1010 1100 0000 0000 0000 0000 which is 40ac0000 in
hex. So stored format is: 00->00->ac->40

Is This Answer Correct ?    27 Yes 2 No

posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0..

Answer / govind verma

i think mr sandeep this value stored in this manner
0100 0000 1010 1100 0000 0000 0000 0000 which is 40ac0000


float takn 4 byte in memory in program p=(char*)&a casting this to char type nw p(it char ponter its point to i byte value) point to lower byte of the a(5.375) which is 0000 0000
p[0]-> contain the fist lower byte data 00(bcoz print bye the hexa formate specifier withe 2 width)
p[1]->contain 00
p[2]-> contain ac
p[3]->contain 40

then output becom ...0000ac40

Is This Answer Correct ?    7 Yes 0 No

Post New Answer

More C Code Interview Questions

main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); }

1 Answers  


write a program for area of circumference of shapes

0 Answers  


why the range of an unsigned integer is double almost than the signed integer.

1 Answers  


main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }

3 Answers  


write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

2 Answers   TCS,






Design an implement of the inputs functions for event mode

0 Answers   Wipro,


Is it possible to print a name without using commas, double quotes,semi-colons?

7 Answers  


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }

3 Answers   Hexaware,


Sorting entire link list using selection sort and insertion sort and calculating their time complexity

1 Answers   Infosys, Microsoft, NetApp,


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

0 Answers   Mbarara University of Science and Technology,


pls anyone can help me to write a code to print the values in words for any value.Example:1034 to print as "one thousand and thirty four only"

2 Answers  


There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen(“somefile.dat”,”r”); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }

1 Answers  


Categories