c - How exactly can I produce the output for this? -
question: if binary equivalent of 5.375 in normalised form 0100 0000 1010 1100 0000 0000 0000 0000, o/p of following program`:
#include <stdio.h> int main(void) { float = 5.375; char * p; int i; p = (char*)&a; (i = 0; <= 3; i++) printf("%02x\n",(unsigned char)p[i]); return 0; } this question in 1 of textbooks , has 4 options associated it. here, have several doubts:
- what
pcontains? pointer to? - what
02xmeans? - won't actual
o/pdepend on whether machine little endian or big endian?
anyways, answer given is: 00 00 ac 40.
thanks!
char* p;meansppointercharvariable, , have:p = (char*)&a;so
pstores address (&) of variablea.%02x- convert unsigned integer hexadecimal form capital a-f letters (x), show 2 "digits" (2) preceding zeros (0), more here http://en.cppreference.com/w/c/io/fprintfit should depend, output
00 00 ac 40little endian,40 ac 00 00big endian. here https://en.wikipedia.org/wiki/endianness , here https://en.wikipedia.org/wiki/floating_point see how floating point numbers stored in memory.
Comments
Post a Comment