0
 #include <stdio.h>
 main() {
   if (sizeof(int) > -1)
       printf("True");
   else
       printf("False");
}

Can anybody tell me why this code gives answer as False while the size of integer is 4.

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Adi
  • 61
  • 10
  • 5
    sizeof returns an unsigned value, so compiler will interpret right hand side as unsigned too and will make it a very large positive number. See live demo here : https://godbolt.org/z/vo6qhd588 (note the value : 4294967295, that's your "-1") – Pepijn Kramer Nov 18 '21 at 05:05
  • 3
    @PepijnKramer That really should be added as an answer. – Alan Nov 18 '21 at 05:06
  • 3
    @PepijnKramer: That's an answer, not a comment. You should post it as such. – Ken White Nov 18 '21 at 05:07
  • @PepijnKramer I agree with the others, you should post an answer. But to be a *good* answer you should explain why the -1 is being cast to unsigned rather than sizeof being cast to int. – Mark Ransom Nov 18 '21 at 05:12
  • Note that for C++, you should be using `` instead of ``. Formally speaking, the latter doesn't exist in C++. – Brian61354270 Nov 18 '21 at 05:25
  • 1
    Please tag this C, it has nothing to do with C++. – Andrej Podzimek Nov 18 '21 at 05:31

0 Answers0