Assignment Statement

An assignment statement uses the = operator to store a value in a variable. It follows the syntax: 

variable = expression;.

 

  • Right-to-Left Evaluation: The expression on the right is calculated first, and the result is stored in the variable on the left.
  • Initialization: The first time a variable is assigned a value.
  • Reassignment: Changing the value of an existing variable.

 

int x = 10;      // Initialization

x = x + 5;       // Reassignment: x is now 15

 

 



Summary
Assignment stores a value into a variable.
= is basic assignment.
Compound operators combine operation + assignment.
RHS evaluated first.
Must follow data type compatibility rules.