If I declare two arrays, one on the stack and one on the heap, I get different behavior when printing the variable name (in gdb if that matters).
int array_on_stack[5];
int * array_on_heap = new int[5];
Now in gdb I step through each line of code and then print the variable name, expecting to get the memory address for each.
print array_on_stack
print array_on_heap
But for array_on_stack
it prints the contents of the array and not the memory address. In order to get the memory address I need the command print &array_on_stack
. This suggests that array_on_stack
is not a pointer. Can some explain the difference between these two declarations in terms of how to access their memory address and why this is the case?