1. Technology
Send to a Friend via Email

Compound Assignment Operator

By

Businesswoman working on laptop
Atanas Bezov/E+/Getty Images
Definition:

Compound assignment operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. They perform the operation on the two operands before assigning the result to the first operand. There are eleven compound assignment operators:

 +=   assigns the result of the addition.
 -=   assigns the result of the subtraction.
 *=   assigns the result of the multiplication
 /=   assigns the result of the division.
 %=   assigns the remainder of the division.
 &=   assigns the result of the logical AND.
 |=   assigns the result of the logical OR.
 ^=   assigns the result of the logical XOR.
 <<=  assigns the result of the signed left bit shift.
 >>=  assigns the result of the signed right bit shift.
 >>>= assigns the result of the unsigned right bit shift.
 
Examples:

To assign the result of an addition operation to a variable:

 //add 2 to the value of number
 number = number + 2; 

Using the compound assignment operator "+=" to do the same thing:

 //add 2 to the value of number
 number += 2; 

Glossary:

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  1. About.com
  2. Technology
  3. Java
  4. Java Glossary
  5. C
  6. Compound Assignment Operator - Definition

©2014 About.com. All rights reserved.