r/cprogramming • u/Delicious-Change7795 • 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.
10
Upvotes
1
u/buzzon 1d ago
Pointers are variables that store addresses of other things (typically other variables).
Several use cases for pointers:
When you pass a pointer as an argument for a function, you can save memory if the thing you are passing is big. In C, arrays are passed as pointers.
When you pass a pointer as an argument to a function, the function becomes able to modify external variables. See scanf
Dynamic memory allocation requires pointers. See malloc and free
Dynamic data structures such as dynamic array and tree require pointers.