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
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 |
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 |
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above
Write a routine to implement the polymarker function
Write a program to model an exploding firecracker in the xy plane using a particle system
main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }
How to return multiple values from a function?
program to find magic aquare using array
Given n nodes. Find the number of different structural binary trees that can be formed using the nodes.
16 Answers Aricent, Cisco, Directi, Qualcomm,
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }
Under linux environment can u please provide a c code for computing sum of series 1-2+3-4+5......n terms and -1+2-3+4-5...n terms..
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)); } }
Find your day from your DOB?
15 Answers Accenture, Microsoft,
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }