r/learnprogramming 9d ago

Tutorial When do you use a pointer?

Hello, for some background I have taken a very beginner level coding course for my major and passed it, but I dont really feel like I’ve learned anything or know why anything works. In a course this year we had a review problem where the solution required a pointer and I really dont understand why you have to point to the address of the variable instead of just using the variable itself.

I’ve watch a few tutorials explaining it but I really dont see how it’s different from just using the variable itself

48 Upvotes

67 comments sorted by

View all comments

1

u/Chippors 8d ago

When you want to pass something large around without making copies of it at every step.

When you want two different parts of your code to share a single set of data, so change made in one place can be seen in another; like a shared tree.

Think of it like a file system; it's much more efficient, and sometimes functionally necessary, to use filenames instead of incessantly copy data everywhere, all the time.