To assign values to the variables, assignment operator (=) is used.
Syntax of assigning values:
Variable_name = value;
Example of assigning values:
Int i , j;
j = 5 ;
i = 0 ;
It is also possible to assign a value at the time of declaration.
int i = 5;
More than one variable can be initialized in one statement using multiple assignment operators.
e.g. j = m = 2;
There could be an exception while using multiple assignment operators.
e.g. int i , j = 2 , k;
here the assignment will be i = 0 j=2 and k = garbage value
An example program which shows the example of assignments:
|Output of the Program:|