# How expression a==b==c (Multiple Comparison) evaluates in C programming?

Since C language does not support chaining comparison like a==b==c; each equal to operator (==) operates on two operands only. Then how expression a==b==c evaluates?

According to operators associativity equal to operator (==) operates from left to right, that means associativity of equal operator (==) is left to right.

Expression a==b==c is actually (a==b) ==c, see how expression (a==b) ==c evaluates?

- (a==b) will be compared first and return either 1 (true) or 0 (false).
- Then value of variable c will be compared with the result of (a==b).

**Consider the following program**

#include <stdio.h> int main(){ int a,b,c; a=b=c=100; if(a==b==c) printf("True...\n"); else printf("False...\n"); return 0; }

Output

False...

### How output is "False..."?

See the program, the values of a, b and c is 100 and you are thinking **how condition is false here** and **why output is "False..."**?

The expression is a==b==c which will evaluates like (a==b)==c now **what will be the result?**

- The result of (a==b) is 1 (i.e. true).
- And (1)==c will be 0 (i.e. false) because the value of c is 100 and
**100 is equal not to 1**.

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

**Ad:**
Are you a blogger? Join our Blogging forum.