Assignment Operator



Assignment operator is used to assign values to variables. This operator is denoted by "=" single equal sign. Precedence for assignment operator is right to left.


Syntax of assignment operator:


variable = expression ;
variable = value ;

Assignment operator assign right side value to left side variable. In case of first syntax expression is evaluated and result is stored in variable. Both side must be compatible to each other.

Multiple assignment can be done using assignment operator.


	//file:assign.java
	//www.jgyan.com
class assign
 {
  public static void main(String arg[])
   {
     int x,y,z;
	 x=y=z=20; // all variable will be initialised to 20;
	 System.out.println("x:"+x);
	 System.out.println("y:"+y);
	 System.out.println("z:"+z);
   }
 
 }
/* Output:
  x:20
  y:20
  z:20
*/

Use of Comma operator

Comma operator is used to separate values from one another. Let's have a look on program given below

	//file:assign.java
	//www.jgyan.com
class assign
 {
  public static void main(String arg[])
   {
     int x=12,23,34,45,56;
	 
	 System.out.println("x:"+x);
   }
 
 }
/* Output:
  x:56
*/