# Latest content was relocated to https://bintanvictor.wordpress.com. This old blog will be shutdown soon.

## Saturday, April 27, 2013

### equivalence of array^pointer? my take

Update -- the spreadsheet is a newer post.
------------
First let's clarify what we mean by "pointer".

Q: an array name is comparable to a pointer ....? Nickname? PointerObject? or PureAddress?
%%A: an array name like myArray is nickname for a pure address. See post on 3 meanings of "pointer". However, in this post we are comparing myArray with a myPointer, where myPointer is ... either a PointerObject or PureAddress

The apparent "equivalence" of array vs pointer is a constant source of confusion. Best (one-paragraph) pocket-sized summary -- http://c-faq.com/aryptr/practdiff.html

http://c-faq.com/aryptr/aryptrequiv.html is a longer answer.

#1 (principle dealing with the confusion) physical layout. When in doubt always go back to fundamentals.

A simple array on the stack is a permanent name plate [2] on a permanent block of memory, physically dissimilar to a pointer Variable. However, Pointer Arithmetic and Array Indexing are equivalent. I feel AI is implemented using PA.

#2) syntax

Pointer variable is syntactically a more _flexible_ and more powerful construct than array. However, the strong syntactical restriction on array is a feature not a limitation. Look at strongly typed vs dynamic languages.

I feel most operations on an array is implemented using pointer operations. (Not conversely -- Many pointer operations are syntactically unavailable on arrays). Specifically, Passing an array into a function
is implemented by pointer bitwise copy.

That's the situation with arrays on the Stack. On the heap situation is more confusing. Consider "new int[5]" -- return value Must be saved in a pointer variable, but the underlying is a nameless array. In contrast, see [2] above. Also, that pointer variable could rebind/reseat.