k++ post increment will return 1 and will increase the value of k by 1. ++k pre increment will increase the value of k=2 by 1. So the sum will be equal to 4.
Unary operators are of a higher priority than binary ones. Operators with the same precedence are calculated from right to left. Post increment and pre increment are calculated differently for the same value of the operand.
Login in to like
Login in to comment