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

#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }

2 Answers  


int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }

3 Answers   Cisco, HCL,


/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }

4 Answers  


void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }

2 Answers  


struct Foo { char *pName; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName); } a. Your Name b. compile error c. Name d. Runtime error

3 Answers   HCL,






void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above

1 Answers   HCL,


How to read a directory in a C program?

4 Answers  


void main() { int const * p=5; printf("%d",++(*p)); }

3 Answers   Infosys, Made Easy, State Bank Of India SBI,


write a program to count the number the same (letter/character foreg: 's') in a given sentence.

2 Answers  


Write a program that produces these three columns sequence nos. using loop statement Sequence nos. Squared Squared + 5 1 1 6 2 4 9 3 9 14 4 16 21 5 25 30

1 Answers   GoDB,


main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

3 Answers   GNITC,


write a program in c language to get the value of arroy keys pressed and display the message which arrow key is pressed?

1 Answers  


Categories