What is the difference between = (Assignment) and == (Equal to) operators
The “=” is an assignment operator is used to assign the value on the right to the variable on the left.
a = 10; b = 20; ch = 'y';
Value of a is 10
The ‘==’ operator checks whether the two given operands are equal or not. If so, it returns true. Otherwise it returns false.
5==5 This will return true.
a and b are not equal
The differences can be shown in tabular form as follows:
|It is an assignment operator.||It is a relational or comparison operator.|
|It is used for assigning the value to a variable.||It is used for comparing two values. It returns 1 if both the values are equal otherwise returns 0.|
|Constant term cannot be placed on left hand side.
Example: 1=x; is invalid.
Constant term can be placed in the left hand side.
Example: 1==1 is valid and returns 1.