Unary operator

 Unary operator in java

There are many types of operators in java :

  1. Arithmetic operator 
  2. Unary operator
  3. Relational operator
  4. Logical operator
  5. Assignment operator
  6. Ternary operator
  7. Bitwise operator

Unary  Operator :

 Unary operator is used with a operand . or only one operand or variable is used.  

Unary operator is also divided in two types : 

  • Increment operator
  • Decrement operator    

Increment operator : Increment operator is used to increment the value by 1.or  in increment operator the value of operand is increased by 1. 

Types of increment operator :
a .pre-increment 
b. post increment

a. pre-increment : In this the value of  operand is firstly increased by 1 then we use the value.

Syntax: + + operand ;

example : + + a ;  If the value of a is 5 , first value of a is increased by 1 means 6 . Then we use the value of a in operation .



b. post-increment : In this the value of operand is used first then the value is increased by 1.

 Syntax : operand + +;

example : a + +; If the value of a is 5 , first it uses the value of a then the value is increased by 1.


Decrement operator : decrement operator is  used to decrement the value by 1.

Type of decrement operator:

a. pre-decrement
b. post-decrement

a. pre-decrement : It first decrease the value then use the value. 

Syntax : - - operand; example : - -a ; if the value of a is 5 ,first it decrease the value by 1 means 4 , then use the value .


b. post-decrement : It first uses the value of operand then decrease the value by  one.

Syntax: operand - -;  example : a - -; first it uses the value  then the value is decreased by 1 . 




Post a Comment

have you any doubt then ask.

Previous Post Next Post