开发者

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

开发者 https://www.devze.com 2023-01-10 11:37 出处:网络
This question already has answers here: float to int unexpected behaviour (6 answers) Closed 6 years ago.
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

精彩评论

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

关注公众号