0

The function that I'd like to call is as follows.

void func(int rows, int columns, int matrix[rows][columns]) {
    cout << matrix[rows-1][columns-1] << endl;
}

The Clion compiler told me that the real type of the matrix is int(*)[columns]. I tried many ways to pass the parameter but all failed when run the func. Here are some of my ways of passing parameters. enter image description here

enter image description here

It seems that the length of the array pointed to by the formal parameter matrix is a variable. But should't an array pointer should declare the size of columns? Why the func could pass compilation? If this is reasonable, how to pass parameters to func?

LoveAndShare
  • 55
  • 1
  • 6
  • The function template described in the target only takes a 1D array, but it's straightforward to have it take a 2D array instead. – cigien Mar 01 '22 at 04:20
  • The function declaration you are showing is valid in C, but not in C++. How to call the function is not the issue. You cannot write a function like that in standard C++ in the first place. – user17732522 Mar 01 '22 at 04:43

0 Answers0