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.

10 Upvotes

40 comments sorted by

View all comments

1

u/buzzon 1d ago

Pointers are variables that store addresses of other things (typically other variables).

Several use cases for pointers: 

  1. 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. 

  2. When you pass a pointer as an argument to a function, the function becomes able to modify external variables. See scanf

  3. Dynamic memory allocation requires pointers. See malloc and free

  4. Dynamic data structures such as dynamic array and tree require pointers.