Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, i++ is unary operator or arithmetic operator?

I have searched the web and it gives me a divide answer. Some said it is only an unary operator and some said it is an arithmetic operator. Thanks

like image 339
Ko Ye Avatar asked Mar 29 '26 01:03

Ko Ye


2 Answers

These classifications don't contradict each other.

++ is an unary operator, as it applies to a single operand.

++ is also an arithmetic operator, as it applies to a number and performs an arithmetic operation (incrementing the number by one).

like image 150
Mureinik Avatar answered Mar 31 '26 05:03

Mureinik


I think it won't be a mistake to call i++ both Arithmetic and Unary Operator.

However, Oracle doc here distinguishes and classifies ++ as Unary operator.

like image 34
HoRn Avatar answered Mar 31 '26 04:03

HoRn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!