You can't pass arrays by value in c, so pointers must be used? Here is the code:
#include <stdio.h>
#define N 5
void printArray(int array[N][N]) {
for(int i = 0;i < N;i++) {
for(int j = 0;j < N;j++) {
printf("%d", &array[i][j]);
}
}
}
int main() {
int array[N][N];
for(int i = 0;i < N;i++) {
for(int j = 0;j < N;j++) {
array[i][j] = 8;
}
}
printArray(array);
return 0;
}
What actually happens when the program is compiled?
Is it the same as doing this?
#include <stdio.h>
define N 5
void printArray(int* array, int rows, int cols) {
for(int i = 0;i < rows;i++) {
for(int j = 0;j < cols;j++) {
printf("%d", &array[i * cols + j]);
}
}
}
int main() {
int array[N][N];
for(int i = 0;i < N;i++) {
for(int j = 0;j < N;j++) {
array[i][j] = 8;
}
}
printArray(&array[0][0], N, N);
return 0;
}