Joseph A. Marrero wrote:
> This is one of the strage parts of C/C++. I thought
> array_name[idx] notation was syntactic sugar for the
> *(array_name + idx). The question is how different are they
> with respect to their layout in memory? Some would argue
> that they are not different at all except for whether they
> are on the stack or the heap. Maybe this is something I
> don't understand at all, but I believe both are arrays.

The notation is the same.  You may wish to compile some code to 
assembler output with your compiler to see that the same memory is 
accessed/referenced.

The stack and heap have nothing to do with this.  I recommend reading 
"Safe C++ Design Principles" (free e-book for c-prog members) Chapter 3 
(Memory) for a better grasp on how pointers operate, but this is the 
relevant quote:

"The simplest description of a pointer is a storage mechanism that 
stores a value that is the address of another location in memory."

My goal in that chapter is to cause the reader to view memory as a 
liquid resource and pointers access specific points within the "liquid". 
  array_name[idx] is the same thing as *(array_name + idx)...you are 
(temporarily) incrementing the address array_name points to by the 
amount stored in "idx" and then accessing the data at that address.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* VerifyMyPC 2.0
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.

Free for personal use, $10 otherwise.
http://www.CubicleSoft.com/VerifyMyPC/

Reply via email to