Yes it is the same. This is guaranteed by the operator precedence rules in standard C, ISO 9899:2011 6.5/3. A parenthesis is a primary expression with the highest precedence possible (6.5.1), higher than the postfix ++ operator (6.5.2), which in turn has higher precedence than the = operator (6.5.16).
Meaning that all of these are 100% equivalent:
z = y++;
(z) = y++;
z = (y++);
(z) = (y++);
(z = y++);
All of these cases will evaluate y, assign that value to z, then increment y by 1.
(Postfix ++ behavior is defined as: "The value computation of the result is sequenced before the side effect of updating the stored value of the operand.")
Note however that it is considered bad practice to mix the ++ operator with other operators, since it has the built-in side effect of updating the value. This can easily create bugs, for example y=y++;
would have been a severe bug. In addition, multiple operators on a single line is often hard to read.
The canonical way to write that expression is therefore:
z = y;
y++;
z = (y++,y);
You could ask your teacher "what is a sequence point" and if they can't answer, they probably shouldn't be teaching C. – Yclepty++
has to be evaluated before its result can be assigned toz
, regardless of the parentheses. Your teacher is simply confused over what the result ofy++
should be. – Madaih