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() { extern int i; i=20; printf("%d",i); }

1 Answers   Value Labs,


Find your day from your DOB?

15 Answers   Accenture, Microsoft,


main() { printf("%x",-1<<4); }

3 Answers   HCL, Sokrati, Zoho,


void ( * abc( int, void ( *def) () ) ) ();

1 Answers  


main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }

1 Answers  






main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }

1 Answers  


What is the output for the following program main() { int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }

1 Answers  


main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); }

1 Answers  


#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }

0 Answers   Student,


#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }

1 Answers  


Write a C program to add two numbers before the main function is called.

11 Answers   Infotech, TC,


void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget it\n"); }

3 Answers   Accenture,


Categories