Just about everyone reading this is probably familiar with these three key facts about C:
- When you mention the name of an array in an expression, it evaluates (most of the time) to a pointer to the array's first element.
- The "array subscripting" operator
[]
works just as well for pointers as it does for arrays. - A function parameter that seems to be an array actually declares a pointer.
These three facts are absolutely central to array and pointer handling in C. They're not even three separate facts; they're interlinked facets of one central concept. It is not possible to do even fairly basic C programming properly without a decent understanding of this concept.
My question today is simply, What is the name for this concept?
I supposed I'm old-fashioned, but I've always called it "The equivalence between arrays and pointers in C", or "array/pointer equivalence" for short. But I've learned that you almost can't say those words on SO; they're pretty much taboo.
This may seem like an abstract or philosophical question, so to frame it more concretely, what I'm looking for is is a simple noun or noun phrase I could use in the sentence "Yes, due to _____, array subscripting can be thought of as syntactic sugar for pointer arithmetic", in answer to, say, this question.
(But please note that I am not looking for answers to that question, or for answers to the question "What's wrong with the word 'equivalence'?". Yes, I know, it can mislead learners into imagining that arrays and pointers are somehow the same. I did have that confusion in mind when I wrote this FAQ list entry.)
[]
or the (unary)*
operators. Most people nowadays appear to think in terms of array and pointer objects, causing the confusion. (because these objects are not equivalent) IMHO, IANALL. – Epirogenychar *a = "hi";
andchar a[] = "hi";
would mean exactly the same thing – Kinson