0
int Ma_Multiplication(int A[][], int B[][], int size){
    int C[size][size];
    for( i = 0 ; i< size ; ++i){
        for( j=0 ; j< size ; ++j){
            C[i][j] = 0;
            for( k = 0 ; k < size; ++k)
                C[i][j] = C[i][j] + (A[i][k]*B[k][j]);
                printf("%d ",C[i][j]);           
            printf("\n");
        }
}

I wrote this function to calculate multiplication of 2 matrices. But when I debugged, it told me this:

error: array type has incomplete element type 'int[]'        
    4 | int MATRIX(int A[][], int size){
      |                ^

Could anyone can explain this? Thank u so much!

NewbieBoy
  • 73
  • 4

1 Answers1

1

C does not allow declaration of arrays with element of incomplete type. Thus int A[] is ok. However, int A[][] is not because it's element type is int[] which is incomplete.

To fix I suggest fully defining the parameters using VLA types:

int Ma_Multiplication(int size, int A[size][size], int B[size][size]) {
  ...
}

If you want to keep an original ordering of parameters you must use an extension (GCC and CLANG) allowing to declare the parameters.

int Ma_Multiplication(int size; int A[size][size], int B[size][size], int size)

This extension may get mainlined into upcoming C23 standard

tstanisl
  • 13,520
  • 2
  • 25
  • 40