Explain the difference between (i)= , == operators (ii) /,// operators
both.
Answers
Answer:
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 differences 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’s or variable’s value to the left side variable.
Let's understand by 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 assigned 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 side expressions, return 1 if they are equal other will it will return 0.
Let's understand by example:
int x,y;
x=10;
y=10;
if(x==y)
printf("True");
else
printf("False");
When expression x==y evaluates, it will return 1 (it means condition is TRUE) and "TRUE" will print.
Conclusion
So it's cleared now, ,both are not same, = is an Assignment Operator it is used to assign the value of variable or expression, while == is an Equal to Operator and it is a relation operator used for comparison (to compare value of both left and right side operands).