Correct way of passing 2 dimensional array into a function

You should declare your function like this:

void display(int p[][numCols])

This C FAQ thoroughly explains why. The gist of it is that arrays decay into pointers once, it doesn’t happen recursively. An array of arrays decays into a pointer to an array, not into a pointer to a pointer.

Leave a Comment