Home > Back-end >  C array initialization
C array initialization

Time:11-06

Source: https://zhidao.baidu.com/question/380723280.html

Int a []={1, 2, 3}; This way initialization, wrote several elements in the braces so there are several elements in an array, is equivalent to an int a [3]={1, 2, 3}


Int a [3]={0}; This is a, all the elements in the initialized to zero.
Int a [4]={1, 2}; This is to initialize a [0] 1, initialize a [1], 2 other initialized to 0



Note that if you don't initialize, the value of the elements in the array is not zero, but an uncertain value

CodePudding user response:

Int a [3]={0}; Just a [0] initialized to 0

CodePudding user response:

Part of the initialization, the rest is 0

CodePudding user response:

Not you think so, int a [3]=0, is to make the three elements are initialized to zero

CodePudding user response:

Wrong, is a int a [3]={0};

CodePudding user response:

Int a [3]={0}; The three elements are initialized, the first element is initialized to the specified value 0 is a [0]=0; Other two elements initialized to the default value is 0, the default value is 0 because constants {0} will stand in the DS data space of the three elements (DS uninitialized data when the default value is 0, the data stored on disk. EXE files, loaded into memory after the corresponding element 0), but this way of initialization is not recommended, because {0} to steal with the DS of memory, and the data section of the DS is not infinite, steal much use will cause no memory to store the global or static variables, the compiled connection would not be successful, can not believe the change in the function definition more array like this:
  • Related