c++ - 以下代码片段的行为是什么?

标签 c++ c pointers floating-point

<分区>

如果我不小心用 C/C++ 编写了以下代码,其行为和输出会是什么,

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

最佳答案

垃圾,越来越垃圾。

如果你做了以下事情,你会得到一些有意义的东西

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

关于c++ - 以下代码片段的行为是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3409823/

相关文章:

c++ - 为什么 char 指针变量可以初始化为字符串,而 int 指针变量不能初始化为整数数组?

c - 在 C 中获取临时(复合文字)参数的地址

c - 错误 : request for member 'valore' in something not a structure or union

c++ - 从链表c++中删除最后一个节点

c++ - 什么时候在 C++11 lambda 的定义中需要明确命名的变量捕获?

c - 如何在 C 中为素数筛选算法设置可变长度数组?

c - C 中的快速排序,带有霍尔分区

c - 将节点插入到链表的尾部

c++ - 虚拟析构函数 : Not Working?

c++ - 查找数组中的最小元素及其索引