- 4

C code

What is the output of this C code? #include <stdio.h> main() { if (sizeof(int) > -1) printf("True"); else printf("False"); } a) True b) False

9th Mar 2022, 3:20 PM
Abhishek
Abhishek - avatar
2 Answers
+ 1
Try it in playground.. What's your doubt here? edit: if your doubt is why False as output? then sizeof(int) returns a long unsigned int type value 4 . In expression evaluation, first the data operand values are all automatically upcasted to higher datatype. so -1 will be upcasted to unsigned long int which is 2^32-1 and it is greater than sizeof(int) (=4 mostly) in any machine. so it outputs False edit: #include<stdio.h> int main(){ if(sizeof(int) > -1) printf("True"); else printf("False"); printf("\n%lu > %lu", sizeof(int),-1); //converted values return 0; }
9th Mar 2022, 3:23 PM
Jayakrishna 🇼🇳
0
Depends on how C evaluates (int)
9th Mar 2022, 3:37 PM
Brave Tea
Brave Tea - avatar