Home » C Popular & Interesting Questions

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

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions