0

I don't understand that;what will be the output;

#include<stdio.h> #include<stdbool.h> int main(){ bool x=3>2; bool y=5>3; printf("%d",x+y); return 0; }

1st Aug 2021, 9:59 AM
Devil Sniper
Devil Sniper - avatar
4 Answers
+ 1
bool x=3>2 here 3 is greater than 2 it means this will give true or 1 same with 5>4 this is true and 1 will assign to y and x so x+y=1+1=2
1st Aug 2021, 10:01 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Thanks Martin Taylor for correcting my misconceptions
1st Aug 2021, 10:38 AM
Atul [Inactive]
+ 1
Martin Taylor I think results can be predicted in this case because of how _Bool works in C. 1) _Bool is just another integer type, means arithmetic is possible here. 2) To avoid integer overflow, any assignment to _Bool that is not false (0) is by default stored as integer constant 1 ( given the fact that program doesn't redefine the macro to something else, which in this case is not happening ) So the answer in this case should always be 2 on any standard implementation. ref : https://en.cppreference.com/w/c/types/boolean https://code.sololearn.com/c5wkUnD4gZzF/?ref=app
3rd Aug 2021, 4:40 AM
Arsenic
Arsenic - avatar