Pointers and Address?
Hi can anyone tell me whats the difference between this 2 statements?
Code:
float num = 100.75 ;
unsigned int a= *((unsigned int*)&num) ;
//for this I am getting a value like 3247..and so on
and this:
Code:
float num = 100.75 ;
unsigned int a = (unsigned int)num ;
//I am getting 100
why am I not getting the same result in a for both the statements?
Does casting the address to be of int type make it different or something?
I know that floating point numbers are stored differently in memory..
the decimal part and the fractional part are calculated separately then it is normalised..
so when I do that
and I cast the address to be of type unsigned int..
does it just take the binary and convert it to a decimal number so it can be stored in the unsigned int variable?
for the second statement why am I getting a 100 and not a number that looks random, i mean
the floating point number is stored in the same way so why will it just chop off the fractional part and print the decimal part..
is it because in the first statement i am actually trying to change how the floating point value is stored in memory?
thanks
Please make your answer simple as possible . thanks