C中int数组的初始值 [英] initial value of int array in C
问题描述
当像这样在 C 中声明一个数组时:
When declaring an array in C like this:
int array[10];
整数的初始值是多少??我使用不同的编译器得到不同的结果,我想知道它是否与编译器或操作系统有关.
What is the initial value of the integers?? I'm getting different results with different compilers and I want to know if it has something to do with the compiler, or the OS.
推荐答案
如果数组是在函数中声明的,则该值是未定义的.int x[10];
在函数中的意思是:在不做任何初始化的情况下取得10-int大小的内存区域的所有权.如果数组在函数中声明为全局数组或 static
,则所有元素如果尚未初始化,则将其初始化为零.
If the array is declared in a function, then the value is undefined. int x[10];
in a function means: take the ownership of 10-int-size area of memory without doing any initialization. If the array is declared as a global one or as static
in a function, then all elements are initialized to zero if they aren't initialized already.
这篇关于C中int数组的初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!