Many times this question arises what is the difference between = and == operators in C programming language ? Here we are going to tell you exactly what the difference between these two operators are.
Assignment Operator (=)
= is an assignment operator in C, C + + and other programming languages, it is Binary Operator which operates on two operands.
= assigns the value of right side expression or variable to the left side variable.
See example-
x=(a+b);
y= x;
Here, when first expression evaluates value of (a+b) will be assigned into x and in second expression y=x; value of variable x will be a sign into y.
Equal to operator (==)
== is an equal to operator in C and C ++ only. It is binary operator which operates on two operands.
== compares value of left and right side expressions, return 1 if they are equal else it will return 0.
See example-
int x,y;
x=10;
y=10;
if (x==y)
printf (“true”);
else
printf (“false”);