I tried out the following code example from the "Understanding and Using C Pointers" (Reese) book, that illustrates passing a two dimension array pointer to a function:
void display2DArray(int arr[][5], int rows) {
for (int i = 0; i<rows; i++) {
for (int j = 0; j<5; j++) {
printf("%d", arr[i][j]);
}
printf("\n");
}
}
void main() {
int matrix[2][5] = {{1, 2, 3, 4, 5},{6, 7, 8, 9, 10}};
display2DArray(matrix, 2);
When I examine the arr variable using the gdb
debugger during execution, I get:
(gdb) p arr
$156 = (int (*)[5]) 0x7fffffffe1c0
(gdb) p &arr
$157 = (int (**)[5]) 0x7fffffffe198
(gdb) p *0x7fffffffe198
$158 = -7744
What is this negative number -7744
?
I thought that dereferencing the address 0x7fffffffe198
should yield 0x7fffffffe1c0
?