If there is some positive integer literal in my code, say 50, does the compiler consider it as type unsigned int or int?
Asked
Active
Viewed 328 times
2
-
3you have `U` for unsigned, therefore... – Karoly Horvath Mar 21 '14 at 11:11
-
Thanks a lot for this question. – Suraj Jain Dec 30 '16 at 18:05
1 Answers
6
A decimal integer literal is of the first type where it can be represented in int
, long
or long long
.
50
is of type int
.
unsigned literals can be specified using the u
or U
suffix. A decimal integer literal suffixed with u
or U
is of the first type where it can be represented in unsigned int
, unsigned long
or unsigned long long
.
50U
is of type unsigned int
.

ouah
- 142,963
- 15
- 272
- 331
-
-
-
@user2460978 read my answer again, if it cannot be represented in an `int`. – ouah Mar 21 '14 at 11:13
-
C11 §6.4.4.1 5 specifies this in detail. Interestingly, a _hexadecimal_ constant is the first type that fits in `int`, `unsigned int`, `long int`, `unsigned long int`, `long long int`, `unsigned long long int`. – chux - Reinstate Monica Mar 21 '14 at 13:54
-
-
@SurajJain The answer is: it depends. Decimal unsuffixed integer literals are always signed (starting from C99). – ouah Dec 31 '16 at 12:58