Initialization C language two-dimensional array of elements

4 kinds of two-dimensional array array initialization:

A direct branch to the two-dimensional array initial value

Example: A int [. 3] [. 4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};    // recommended to use this easy assignment array

 

Second, all data written a flower in parentheses

例:int a[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};      

 

Third, some elements can be given initial

Example: int a [3] [4] = {{1}, {5}, {9}}; // represents an assignment of the first three rows of the array are: 1,5,9

 

Fourth, all the elements given initial definition of the array is the length of the first dimension can not be specified, but the two-dimensional length should not be spared.

Example: int a [3] [4] = {1,2,3,4,5,6,7,8,9,10,11,12}; // also be written as int a [] [4] 1,2,3,4,5,6,7,8,9,10,11,12 = {};

Guess you like

Origin www.cnblogs.com/jcfeng/p/11263536.html