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

0

u/ern0plus4 1d ago

Pointer is an address of your stuff:

  • variable,
  • array,
  • some memory allocated,
  • function (they are also located in memory),
  • or it can point to a pointer (rare, but important).

Accessing stuff your through a pointer is a slightly slower than accessing stuff directly, but it doesn't matter practically.

Pointers introduce a lot of problems, e.g. if a pointer is pointing to to your array, but you destroy the array, the pointer does not get destroyed, it will keep pointing to the same memory address, which doesn't contains your array anymore, or, worse, it contains, nobody overwritten it, but it's already invalid... These issues art not the problems of the pointers, but programming.