变量的默认值 [英] Variable default values
问题描述
我感到困惑用C编程的一些基本理论:
I'm confused about some basic theory in C programing:
-
什么是不同数据类型的变量的默认值?举例:如果我声明如下什么,可能是根据标准C手动其结果是由传奇丹尼斯里奇博士记录
What are the default values for variables of different datatypes? Example: If I declare as follows what may be the result according to standard C manual which is documented by legend Dr. Dennis Ritchie?
int x;
printf("%d",x);
我知道有些GCC编译器将打印0和一些打印垃圾值。这取决于编译器。请给我答案独特按丹尼斯里奇Ç编程文档。
I knows that some GCC compilers will print 0 and some print garbage values. It depends on compiler. Please give me the unique answer as per Dennis Ritchie C programing documentation.
:同上,请给我解答了浮法,焦炭,双,字符串数组和指针。
Same as above, please give me answers for float, char, double, string, array and pointers.
如果我宣布和打印指针如下:
If I declare and print pointer as follows:
int *pt;
printf("%d",pt);
什么会在屏幕上打印?我用MinGW的GCCcompiler版本3.4.2,并在这我得到一个垃圾值。请帮我在这混乱。
What will be printed on screen? I used MinGW GCCcompiler version 3.4.2, and in that I get a garbage value. Please help me in these confusions.
感谢您。
推荐答案
本地(非静态)变量的值是不确定的,即你不能告诉他们的价值观。使用未初始化的非静态局部变量导致的未定义行为的。
The values of local (non-static) variables are indeterminate, i.e. you can't tell their values. Using an uninitialized non-static local variable leads to undefined behavior.
全局变量和静态局部变量,都初始化为零。宣布的时候当然除非初始化。
Global variables, and static local variables, are zero initialized. Unless initialized when declared of course.
这篇关于变量的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!