2016-01-22 54 views
-4
#include<stdio.h> 

    int i=0, j=0; 

    void main(){ 
     int a[3][5]={1,2,{3,4,6,8},{5,8,9},10,{11,12,13,14},{21,22},23,9,8,7,6,5,4,3};//Array Initialisation 

     for(i=0; i<3; i++){ 
      for(j=0; j<5; j++){ 
       printf("\na[%d][%d]:%d\n", i, j, a[i][j]);//Array Printing 
     } 
    } 
    } 
/*The above code initialises the array with some logic that I'm unable to understand. How are the set elements treated? Please explain */ 
+0

给定边界'[3] [5]',数组定义看起来不正确。 –

+0

@boson请参阅示例[here](http://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm)。在C数组中,每行的长度应该是相同的... – urban

+0

符合应使用的标准int main(void) –

回答

2

你没有得到双维数组的点在C:

int A[2][3] 

是6个的整数元素双维数组的两行声明和三列。这总是如此,第一个方括号中的数字代表行,而第二个方括号中的数字代表列。 要初始化你需要知道这些东西两维数组:

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

正如你可以看到有三个大括号(行),这三个大括号内有5个号码(列)。