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 |
main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }
how to concatenate the two strings
plz send me all data structure related programs
Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }
void main() { char ch; for(ch=0;ch<=127;ch++) printf(“%c %d \n“, ch, ch); }
Code for 1>"ascii to string" 2>"string to ascii"
1 Answers Aricent, Global Logic,
How do you sort a Linked List (singly connected) in O(n) please mail to pawan.10k@gmail.com if u can find an anser...i m desperate to knw...
6 Answers Microsoft, MSD, Oracle,
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h
main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }
main() { int a[10]; printf("%d",*a+1-*a+3); }
int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().
Question: We would like to design and implement a programming solution to the reader-writer problem using semaphores in C language under UNIX. We assume that we have three readers and two writers processes that would run concurrently. A writer is to update (write) into one memory location (let’s say a variable of type integer named temp initialized to 0). In the other hand, a reader is to read the content of temp and display its content on the screen in a formatted output. One writer can access the shared data exclusively without the presence of other writer or any reader, whereas, a reader may access the shared memory for reading with the presence of other readers (but not writers).