= and == in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

= and == in c

Could you explain the output? I understand 1 in the output, that is x value, other two I did not understand: #include <stdio.h> int main() { int x, y=2 , z; x=1; z=x==y; printf("%d %d %d", x, y,z); return 0; }

10th Jan 2019, 6:35 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
1 Answer
+ 3
Like any other C-based language, = is an assignment operator; e.g x = 5; you assign 5 to the "variable" x. == is a comparison operator; which means "is equal to" e.g: a = 3 b = 2 a == b will return false but if both had the value of 3, return true. in this code, z = 0 (x == y) is false. you assign "z" to the bool (x == y); (1 != 2) therefor 0 which is false (1 is true) Hope this helped a little bit!
10th Jan 2019, 6:41 PM
Joery De Loose
Joery De Loose - avatar