3 ms·
Why did people think otherwise? Chapter 5 of K&R[1] is titled Pointers and Arrays and basically explains that arrays and pointers are equivalent. [1]: https://
by pdog 10y ago
Why did people think otherwise? Chapter 5 of K&R[1] is titled Pointers and Arrays and basically explains that arrays and pointers are equivalent.
[1]: https://www.amazon.com/Programming-Language-Brian-W-Kernighan/dp/0131103628/ https://www.amazon.com/Programming-Language-Brian-W-Kernigha...
- deleted 10y ago[deleted]
- notacoward 10y agoThe point of the article is that sometimes they're not equivalent, and that creates a lot of confusion. Please read it before commenting on it.
- ams6110 10y agoI thought the same things as GP. Anyone who has read K&R (as any C programmer ought to have) will know everything in this article.
- notacoward 10y agoI don't think that's true. While I don't have my copy of K&R handy, I don't recall it covering all the subtleties of how assignment and increment operators and sizeof will work differently for something declared as an array vs. something declared as a pointer. At least in the edition I've had, it just had the same "pointers and arrays are equivalent" which is misleading in exactly the way this article describes. Did that get added in your much-later edition?
- mwfunk 10y agoI'd go so far as to say that any C programmer at all (whether or not they've read K&R) will know everything in this article. However, it's probably interesting or useful for people who are either in the process of learning C, or people who have to read and write it occasionally, but never truly learned the language. These are definitely all pain points for people coming to C from higher-level languages.
- kazinator 10y agoArrays and pointers are never equivalent. One is a clump of like-sized objects allocated consecutively; the other is a referential type indicating the location of an object or function.