开发者

what will be behavior of following code snippet? [duplicate]

This question already has answers here: float to int unexpected behaviour (6 answers) Closed 6 years ago.

What will be the behavior and output of the following c开发者_运维技巧ode if i accidentally code so in C/C++,

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


Rubish and more rubish.

You would get something meaningful if you did the following though

 printf("%d\n", (int)a);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜