+ 2

Exam question

İnt main () { int a=5 , b=0 , c=10 , result; result = ( a = b) && ( c > b ) ; printf("%d \n", result) ; } How does this program can be equal to 0? Can you explain it?

14th Apr 2019, 8:57 PM
Osman Uçkan
Osman Uçkan - avatar
2 Antworten
+ 2
It looks like one = is missing. Should it be (a==b)? As it is, a is given the value of b: zero. And zero is evaluated as false. The second part c>b is true, but you wrote a=b AND c>b, so this ends up as false. false gets converted to int (zero) and stored in result.
14th Apr 2019, 9:37 PM
HonFu
HonFu - avatar
+ 1
ın the question ( a = b )
15th Apr 2019, 9:00 AM
Osman Uçkan
Osman Uçkan - avatar