void main()
{
int array[10] = {1,2,3,4,5,6,7};
printf("%p\n",array);
}
Here, the system would allocate a memory in stack equivalent to 10 integers for the array. However, i dont think there is any extra memory allocate for the variable array, i presume array
is a mnemonic for human understanding and coding purpose. If that is the case, how does the printf()
in the statement - printf("%p\n",array);
accept it as though it is a pointer variable?
This confusion becomes more evident as the dimension(s) of the array keeps increasing.
int main()
{
int matrix[2][4] = {{11,22,33,99},{44,55,66,110}};
printf("%p\n", matrix);
printf("%p\n", matrix+1);
printf("%p\n", *(matrix+1));
}
The ouput for one of the program execution was -
0x7ffd9ba44d10
0x7ffd9ba44d20
0x7ffd9ba44d20
So both matrix+1
and *(matrix+1)
, after indirection outputs the same virtual memory address. I understand why matrix+1
address is what it is displaying but i don't understand why *(matrix+1)
is outputting the same address even after indirection!