Small but strange question about "++"

Hi,

I want to increase the value of some elements of an array according to a certain condition. For example the following code:
1
2
3
4
array <int, 100> myArray = {};
myArray.fill(0);
for(int i=1; i<5; i++)
   *(myArray.being()+1) ++;


I was hoping myArray[1] = 5. But it actually did not work. But if I code:
1
2
3
int myVar = 0;
for(int i=1; i<5; i++)
   myVar ++;


Result: myVar = 5. Could someone please tell me why? Thanks in advance.
It's (*(myArray.begin()+1))++; because postincrement has higher precedence than the dereference

You could also use ++*(myArray.begin()+1); or just ++myArray[1];

Last edited on
Thank you Cubbi for your prompt reply. Now I get it!
Topic archived. No new replies allowed.