views:

131

answers:

2

What will be the behavior and output of the following code if i accidentally code so in C/C++,

float a = 12.5;
printf("%d\n", a);
printf("%d\n", *(int *)&a);
+7  A: 

Rubish and more rubish.

You would get something meaningful if you did the following though

 printf("%d\n", (int)a);
torak
+1 for unintentional humour. :-)
Paul R
@Paul R: How did you know it was unintentional? Not saying it wasn't mind you.
torak
@torak: apologies if it was intentional - I thought it was probably just a typo that happened to be quite funny and apposite. :-)
Paul R
@Paul R: No, it wasn't intentional. Actually, I appreciate you letting me in on my own joke. :)
torak
@torak: cool - I may steal your joke at some later date. ;-)
Paul R
Isn't it rubbish and not rubish? Just sayin' ;)
0A0D
A: 

its undefined, because ANSI defines not a relation between sizeof(int) and sizeof(float).