I'm trying to understand how the parentheses affects the precedence in an expression:
int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
auto b = arr;
std::cout << *(++b) << std::endl;
// output : 1
In this code I get the expected output but if I change it to:
std::cout << *(b++) << std::endl;
// output 0
I get 0
as output. Because of the parentheses I though b++
will be evaluated first and then de-referencing will occur. It seems I was wrong, then I removed the parentheses completely and test with *++b
and *b++
and get the same results.Does that mean the parentheses don't affect the precedence on this kind of expressions ? And why are the results of this two expressions are equivelant:
*(b + 1)
*(++b)
But it's not the case with *(b++)
?