What is Assignment operator
Assignment operator (=) is used in programming to assign a value to a variable. This operator assigns the value on the right side to the variables on the left side.
Let us understand this through an example: Let's say you have a variable ‘x’ and you want to store ‘10′ in it: then
int x;
x = 10;
Get Freelancing_Vibes’s stories in your inbox
Join Medium for free to get updates from this writer.
int x; means that we have created an integer type variable ,x = 10; means that we have assigned the value 10 to x.
Example:
Imagine you have an empty glass and you are filling it with water. Here, glass is a variable and water is its value. When you pour water into the glass, you "assign" the water to the glass. Similarly, when you use ‘=’ in programming, you are storing a value in a variable.
Multiple Assignments: You can also assign values to multiple variables in one line:
int a, b, c;
a = b = c = 5; , Here, first ‘5′ is assigned to value ‘c’, then value ‘b’ and then to ‘a’. So now the value of all variables is ‘5′.
Important Point:
There is a difference between assignment operator (‘=’) and equality operator (‘==’) ‘=’ is used to assign value. ‘==’ is used to compare two values (e.g. ‘x == 10′ will check whether the value of ‘x’ is ‘10’ or not). I hope that you have introduced the use of assignment operator to the society!









