Pointers - not sure what this means...

Hello!

I have a very small question, I was just wondering why there is an asterisk besides (coins+count) and what exactly it does. I know it's a pointer but that's basically it. Thank you in advance!

1
2
3
4
for (int count = 0; count < NUM_COINS; count++)
cout << *(coins + count) << " ";
 cout << endl;
 return 0;
This code is just using pointer arithmetic to interate through an array. That asterisk is the dereference operator.
Got it, thank you very much!! :D
Just some extra info - Pointer arithmetic is something that you should understand, but has no benefit most of the time in C++ and will usually be worse as it hurts readability. But you might stumble across code that uses it if you're dealing with some C code bases so it's good to be able to recognize and understand how exactly it works.
Last edited on
Oh, ok! I will definitely keep this in mind! Thank you very much for the extra information, I really appreciate it :)
Topic archived. No new replies allowed.