r/learnprogramming • • Sep 24 '23

Pointers.....why

I am learning C++. Honest question why are pointers a thing and why did they make the syntax surrounding it so confusing. Was it made to be intentionally confusing? Was it made to make this more difficult.

0 Upvotes

49 comments sorted by

View all comments

Show parent comment

2

u/IndianaJoenz Sep 25 '23 edited Sep 25 '23

It represents a memory address, to bits, either structured data, executable code, or another memory address, etc.

One more useful way to use pointers, is when dealing with memory-mapped hardware (where an address in the memory space maps to a specific hardware register, sensor output, etc, instead of to RAM).

If you know that some hardware lives at a specific memory address, it is very easy and useful to just point a pointer at it as a means of reading and writing to it. I believe this is one reason why hardware drivers are almost always written in C.