+ 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; }
1 Resposta
+ 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!