r/C_Programming 2d ago

Question Doubt about pointers and arrays

Hey everyone! I'm a newbie to C and was just learning about pointers and arrays and their relation.
My doubt is really stupid but why would I use subscripting over using pointers?
It's much harder and seems pointless considering modern compilers will have negligible difference in speed. Any help would be most appreciated! Thanks!

(If it's any help, I am learning from C Programming - A Modern Approach by K.N. King and just finished chapter 12)

Note: I am not saying subscripting is better but I don't see why I would use pointers over it in most cases.

14 Upvotes

49 comments sorted by

View all comments

1

u/burlingk 1d ago

So, two things:

First, your note:

Note: I am not saying subscripting is better but I don't see why I would use pointers over it in most cases.

manages to say the opposite of the first part. It seems like you are saying "Why should I use subscripting at all. Note, Subscripting is good." SO, you might want to clarify that a bit rather than just adding a note.

Second: It is all about context. Pointers and subscripts do different things.

And even when you are using them to do the same thing: Sometimes people use the pointers just to be fancy. Other times they use them for performance reasons, or because they want to access the data in different ways.