+10

sizeof(int) > -1

https://code.sololearn.com/cBIA2mCW0F1q/?ref=app why ?

8/9/2019 10:06:53 PM

Mouadh Ben Abdallah

5 Answers

New Answer

+9

The sizeof operator returns a type of size_t. size_t is an unsigned data type. When -1 is converted to an unsigned data type, it will become the largest maximim value for that datatype. For a 32-bit build, that -1 will become 4,294,967,295 which is bigger than 4 (size of an int). In general: don't compare size_t to an int, and especially don't compare size_t to a negative int.

+4

The return type of sizeof operator is size_t data type, the definition of size_t depends on its implementation, but it usually an unsigned type, in Sololearn, I think it's unsigned long long int. Because the return type is an unsigned type, the number -1 will be evaluated as positive. The format of -1 itself is (in Sololearn size_t type) 0xFFFFFFFFFFFFFFFF, which is practically the biggest number it can get. So, 4 is definitely not bigger than that

+3

Yes, compare with zero if you like but not a negative number.

+2

+1

https://code.sololearn.com/cG495gBCZ332/?ref=app this is a solution to prevent the compiler from the logical error if u need more help to understand why you are welcome