Difference between i++ and (i)++ in C

  • A+
Category:Languages
int i = 3; int j = (i)++; 

vs

int i = 3; int j = i ++; 

Though both of the above examples store 3 in j, is there a difference between how the above two cases are evaluated?

Since i is an int, do the () cause the first case to be evaluated as an expression, which would be equivalent to incrementing an rvalue? Or is it undefined behaviour and just happens to store 3 in j?

Or am I overthinking it and its just a simple postfix?

 


i++ and (i)++ behave identically. C 2018 6.5.1 5 says:

A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: