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

Is a = b == c possible to write in c? – also in this Example learn to a==b==c (Multiple Comparison) evaluates in C programming.

Is a = b == c possible to write in c language?

Expression ‘A = B == C’ is calculated as ‘A = (B == C)’. Consider inspecting the expression.

  • Assignment operator (=) : It is used to assign the value to the left side variable.
  • Equal to operator (==) : It is used to compare two variables.

Since Main C programming language does not support chaining comparison like x==y==z; each equal to operator (==) operates on two operands only. Then how expression x==y==z evaluates?

Also Read This πŸ‘‰   How to integrate CardConnect payment Gateway with Node JS

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

Expression x==y==z is actually (x==y) ==z, see how expression (x==y) ==z evaluates?

  • (x==y) will be compared first as well as return either 1 (true) or 0 (false).
  • Then value of variable z will be compared with the result of (x==y).

Consider the following example

#include <stdio.h>
int main(){
	int x,y,z;
	return 0;	



How result is “Sorry…”?

See the example, the values of x, y and z is 100 as well as you are thinking how condition is false here & why result is “False…”?

Also Read This πŸ‘‰   how to add edit and delete button in datatable using php?

The expression is x==y==z which will evaluates like (x==y)==z now what will be the result?

  • The result of (x==y) is 1 (i.e. true).
  • And (1)==z will be 0 (i.e. false) because the value of z is 100 and 100 is equal not to 1.

Also Read : JavaScript Arrays & Objects Tips, Tricks And Examples

What does int i=(x,b,z) mean ?

==> x,y will return y 
==> y,z will return z 
==> means (x,y,z) will return z
==> and Last Assign z to variable i which will be actual result.

I hope you get an idea about a = b == c.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.