×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

What is the difference between = (Assignment) and == (Equal to) operators in C?

Difference between Assignment (=) Vs Equal to (==) Operators in C

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).



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.