我得到的输出为-28762。为什么它不是0(零),它应该是整数的默认值?
#include<stdio.h>
#include<conio.h>
void main(){
int a;
clrscr();
printf("%d",a);
getch();
}
最佳答案
虽然您尚未初始化该变量,但该变量确实引用了内存中的位置。
此位置的值转换为整数时会产生一些结果,在您的情况下它是 -28762
请注意,当您声明任何简单数据类型(如 int、float 等)时,就会发生这种情况。
对于用户定义类型和结构等复杂类型,这种情况不会发生。
整数变量不默认为零,除非它们是文件范围或静态的。 请参阅引用链接https://msdn.microsoft.com/en-us/library/y2xtdbay.aspx
If the declaration of z was for an uninitialized static variable or was at file scope, it would receive an initial value of 0, and that value would be unmodifiable.
关于c - Turbo c 中的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44602574/