+ 4

What will be the output of this code? And why?

#include <iostream> using namespace std; int main() { if(sizeof(int)>(-1)){ cout<<"True"; } else{ cout<<"False"; } }

4th Mar 2017, 6:01 PM
Hitesh Garg
Hitesh Garg - avatar
5 ответов
+ 9
I think it is True because if I remember correctly, sizeof(int) = 4 EDIT: Just tried the code on code playground and I was wrong because sizeof returns a value of type size_t which is an unsigned type. Answer is False
4th Mar 2017, 7:01 PM
Alper Tiryakioğlu
Alper Tiryakioğlu - avatar
+ 2
False
4th Mar 2017, 6:51 PM
vishnu
vishnu - avatar
+ 2
False is absolutely right answer.
9th Mar 2017, 4:50 PM
Hitesh Garg
Hitesh Garg - avatar
+ 2
false is right answer becoause the size of operater return the value in unsigned format but it is compared to -1 which is signed format bt this cant not happen u can not compare unsigned with signed therefore the compilor converts the -1 into unisgned which is much grratrr than size of int hence it prints false
22nd Mar 2017, 7:17 PM
satyam sanghi
satyam sanghi - avatar
0
how you say false is absolutely correct answer?
11th Mar 2017, 6:44 AM
Ravibharathi V
Ravibharathi V - avatar