Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 7
    Unless someone can dig up sources from interviews etc., the answer will probably remain opinion-based and speculation, but data structures were a hot topic in other languages at that time (Algol), and those languages did distinguish between pointers and arrays. IIRC it also makes a difference for lvalues vs. rvalues (but I would have to look this up). Commented yesterday
  • 2
    " 0[ptr] == ptr[0] == *ptr " -- this part is actually pretty true (the same or equivalent) in C. Because a[b] is effectively *(a+b), thus no difference between a[b] and b[a]. Commented 20 hours ago
  • It depends on the types of a and b, but as long as one is an integer and the other a pointer, you're fine. a[b] is equivalent to the expression *((a) + (b)). Adding an integer to a pointer gives an address depending on the pointer type, regardless of whether the integer or the pointer comes first. Adding two pointers isn't allowed. Commented 17 hours ago
  • Before addition, integer is multipied by the size of object which the pointer is typed with. Therefore, *(ptr+index) is always fine, the same as ptr[index] or index[ptr]. Commented 16 hours ago
  • Note that BCPL had neither have data-structures nor pointers as in C , instead it had word-pointers (to the pain of Amiga users) so for 32-bit words and 8-bit bytes it means that all pointers were divided by 4. Since C improved that part could that be linked with the syntax change (either because some version had both and needed different syntax, or just to avoid confusion)? Commented 16 hours ago