4 ms·
No, pointers are not arrays. Pointers can point to arrays and, because of the language rules, you can do pretty much anything you can do to an array through poi
by coliveira 6y ago
No, pointers are not arrays. Pointers can point to arrays and, because of the language rules, you can do pretty much anything you can do to an array through pointers, but they are definitively not arrays.
- dnautics 6y agoI think we see the problem here. I've been using C on and off (granted, never formally educated in it) for 20 years now and I don't know the difference.
- coliveira 6y agoAn array is a variable that is declared to contain sequential data (using square brackets and the desired number of elements). It is immutable. A pointer is a mutable variable that can be made to point to anything, and it can be used to reference an array or any of its elements. These are different concepts, although the language allows a lot of operations in common between them.
- dnautics 6y agoI see. I mean, yes I obviously know the difference between pointers and arrays as general CS concepts (and articulated how other languages get it correct), but we're not talking about CS, we're talking about C. Perhaps I should have said in my original context, "array syntax" is the same as "pointer syntax". But while the CS concepts of "array" and "pointer" are indeed different, the C syntax elides the two. C does not track the immutable length of the array for you.
- globular-toast 6y agoI think what you're getting at is that arrays are not really first-class objects in C. Rather it just gives you a bit of syntactic sugar to do the same thing that you could do with pointers anyway. But it's up to the programmer to complete the abstraction.
- coliveira 6y agoNo, I described how it is in C. C has a proper array syntax, although a poor one. The problem is that pointers can do a lot of the same, so people get confused.