c - Variable cast to double in printf produces random output -


i trying see hex representation of floating point numbers , compiled code gcc-4.9.2:

#include <stdio.h>  int main() {   double = 100;    printf("%f %x\n", i, (double)i);    return 0; } 

i surprised find everytime ran code hex value printed out changed. going on? how can safely print hex representation of floating point number?

the %x format specifier requires argument of type unsigned int. you're giving argument of type double. behavior undefined, means far c standard concerned anything can happen -- including changing output other specifiers in same format string.

to print hex representation of floating-point number, copy array of unsigned char , print elements of array.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -