0
C programming(logical operator)
how is this being executed?? please explain.... #include<stdio.h> int main() { int i = -1, j = 1, k ,l ; k = !i && j ; l = !i || j ; printf ( "%d %d", i, j ) ; return 0; }
5 Answers
+ 3
@ifl in c actually 0 is false and anything else is true
generally a boolean is true if its value is 1 and false if its value is 0.
Also your && or || operators will return 0 or 1 depending on the result if it's true or not
Just made a small code to show:
https://code.sololearn.com/c7y8sE0bktk0/?ref=app
+ 1
@Aaron ... duh!
Yes correct I meant non zero values are true. Changed my sentence mid way and did not check before posting.
Thanks for the correction
0
the last line prints i and j which stay unchanged . so -1 and 1.
in C, non zero values are true, so
k is zero and l is 1
(edited to correct typo)
0
if there's k=!5 &&j??
0
in : k=!5&&j
!5 is false and then j is true
false && true is false
So as an integer, k is then 0