Hello Everybody,
so what I always find confusing about pointers, is that everytime someone has tried to reexplain them to me, I feel like I’m getting the Information Backwards.
So if you think you understand what Poimters are, but don’t quite get why were even using them, check this out:
Let’s suppose you have 5 pointers, all pointing to the same memory address:
int MyData = 10;
int *p1 = MyData;
int *p2 = MyData;
int *p3 = MyData;
int *p4 = MyData;
int *p5 = MyData;
So if we read the data Value pointed to by all these pointers, they will all return the value “10”. So, let’s change it!
*p1 = 20;
Now if you read the data value pointed to by all of these pointers, they will all return the value “20”.
What we’re doing with pointers is refrencing data values stored in specific areas of memory.
You can do other stuff with pointers, but just knowing one case for why you might use them, helps me atleast understand their purpose.
Hope this helps and wasn’t actually more confusing.