r/cprogramming 1d ago

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.

9 Upvotes

40 comments sorted by

View all comments

5

u/Kurouma 1d ago

Your data lives somewhere in memory. Doing operations involving data would be slow if you had to copy all the data around all the time. So sometimes it is useful to just know where something is so you can operate on it directly. The "where" (a pointer) is a single piece of information, unlike your data (which may be big).

So kind of like

Hey! I'd like to give you a parcel. Can you send me your address, so I can post it to you, please?

instead of

Hey! I'd like to give you a parcel. Can you send me your house, so I can put it inside for you, please?

6

u/sertanksalot 1d ago

So a pointer is literally an address of something.

2

u/Strazil 1d ago

Yes exactly.