What should be the output of this program and why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What should be the output of this program and why?

#include <iostream> using namespace std; int main() { unsigned int a=23; signed int b=-23; if(a>b){ cout<<"True"; } else{ cout<<"False"; } }

4th Mar 2017, 5:46 PM
Hitesh Garg
Hitesh Garg - avatar
3 Answers
+ 3
output False. because a is unsigned and b is signed. everytime you compare unsigned number with signed number , computer automatically cast signed to unsigned.Therefor,b become (2^32-23) bigger than a.
5th Mar 2017, 2:06 AM
Steven Cai
Steven Cai - avatar
+ 2
false bcoz - 23 is converted into unsigned automatically and hence it has much greater value than 23 hence it prints false
22nd Mar 2017, 7:19 PM
satyam sanghi
satyam sanghi - avatar
+ 1
Should output False as 23 is not greater than 23, but is equal to. a >= b however, would output True.
4th Mar 2017, 6:35 PM
ChaoticDawg
ChaoticDawg - avatar