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*

12
  • What is a pointerunction? Commented Dec 5, 2019 at 17:39
  • 2
    ptr[x] is equivalent to *(ptr+x). This is really a basic syntax question. Commented Dec 5, 2019 at 17:40
  • Does this answer your question? What is the difference between char s[] and char *s? Commented Dec 5, 2019 at 17:41
  • 2
    Because ptr[i] is exactly the same as *(ptr+i), you can also say i[ptr] and kind of freak people out :-) Commented Dec 5, 2019 at 17:54
  • 2
    @RobertS-ReinstateMonica they are the same because the language says so. Arrays are not first-class data types in C - though they are in other languages - and I'm not sure how to explain it more than that. C defined array access notation in terms of derference-pointer plus index. Now it's true that ptr[i] and (ptr + i) are not the same thing - the first accesses the element at the array, while the second only computes the address, but adding the deference *(ptr + i) accesses the element. Commented Dec 5, 2019 at 18:00