turbo c 中的默认值
Default values in turbo c
我得到的输出是 -28762.Why 是不是 0(零),这应该是整数的默认值?
#include<stdio.h>
#include<conio.h>
void main(){
int a;
clrscr();
printf("%d",a);
getch();
}
虽然您没有初始化变量,但变量确实引用了内存中的位置。
这个位置的值在转换为整数时会产生一些东西,在你的情况下它是 -28762
请注意,当您声明任何简单数据类型(如 int、float 等)时,就会发生这种情况。
对于用户定义类型和结构等复杂类型,这不会发生。
整数变量不默认为零,除非它们是文件范围或静态的。
见参考资料 link 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.
我得到的输出是 -28762.Why 是不是 0(零),这应该是整数的默认值?
#include<stdio.h>
#include<conio.h>
void main(){
int a;
clrscr();
printf("%d",a);
getch();
}
虽然您没有初始化变量,但变量确实引用了内存中的位置。
这个位置的值在转换为整数时会产生一些东西,在你的情况下它是 -28762
请注意,当您声明任何简单数据类型(如 int、float 等)时,就会发生这种情况。
对于用户定义类型和结构等复杂类型,这不会发生。
整数变量不默认为零,除非它们是文件范围或静态的。 见参考资料 link 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.