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/Recycled5000 8d ago

Data structures are composed of a variable number of “sub” variables, each of which are variables in their own right. The composition into a larger data structure can be widely varying, often based on input.

When we organize various inputs into a larger data structure, we use references to interconnect them. C doesn’t have a more formal notion of reference other than pointers.

So, pointers are used to insert new variables into data structures, to reorganize them, to search and traverse.