Tuesday, 1 July 2014

Error : array type has incomplete element type

 
array type has incomplete element type

PROGRAM

#include<stdio.h>

int main()
{

    int arr[][]= { {1,2}, {3,4}} ;

    printf(":: %d :: %d ",arr[0][1],arr[1][1]);


    return 0;
}





ERROR STATEMENT GCC

error: array type has incomplete element type


EXPLANATION:

The size of the two dimensional array cannot be initialized when initializing the value for the two dimensional array.




For eg:

int arr[]={1,2,3,4} // valid

int arr[][]={{15,3},{62,5}}; // Not valid in c and c++
int arr[][10]={{1,3},{852,5}}; // valid in c and c++


In more general, the multi dimensonal array size should be mentioned even though we are intialzing the array at the time of declaration.


But the 1st dimension can be left uninitialized.