r/cprogramming • • Sep 12 '26

What are pointers?

I am new to C programming and i came through pointer. So can anyone tell what are they and why we need them? And if u can then can you give me reliable source to learn it.

15 Upvotes

45 comments sorted by

View all comments

Show parent comment

5

u/sertanksalot Sep 12 '26

So a pointer is literally an address of something.

2

u/Strazil Sep 12 '26

Yes exactly.

1

u/musbur Sep 13 '26

And if you have a consecutive bunch (=array) of somethings and p ist a pointer to the first something, then p + 1 is a pointer to the second one and so on. Regardless of how many bytes one something occupies. The compiler knows how big one something is and the "distance" between them in memory (IOW, how they are aligned). It's called pointer arithmetics and is a powerful feature of C.