I read somewhere that default floating point values like 1.2
are double
not float
.
So what are default integer values like 6
, are they short
, int
or long
?

- 195,001
- 40
- 254
- 396

- 1,775
- 5
- 22
- 30
-
I heard that range of `short` and `int` is same. so a value bigger than `int` may come under `long` but what about small values, as they can be `short` and `int` both. – kevin gomes Jan 27 '14 at 14:11
-
By the way, these are normally called "constant expressions" or "integer constants". The phrase "default values" normally implies a standard value like `0` or `0.0` which happens in certain cases (such as defining a `static` variable without an initializer) – Brandin Jan 27 '14 at 14:33
-
1After reading the answers below, test yourself and see if you can explain why `sizeof(4294967295u)` < `sizeof(2147483648)` :) – Lundin Jan 27 '14 at 14:59
3 Answers
The type of integer literals given in base 10 is the first type in the following list in which their value can fit:
int
long int
long long int
For octal and hexadecimal literals, unsigned types will be considered as well, in the following order:
int
unsigned int
long int
unsigned long int
long long int
unsigned long long int
You can specify a u
suffix to force unsigned
types, an l
suffix to force long
or long long
, or an ll
suffix to force long long
.
Reference: C99, 6.4.4.1p5

- 107,303
- 21
- 270
- 254
-
-
@kevingomes There is no suffix for `short`. But if you need it (and you usually don't because conversion is automatic), you can cast to `short`. – interjay Jan 27 '14 at 14:14
Just if someone is interested:
C11 §6.4.4.1/5:
The type of an integer constant is the first of the corresponding list in which its value can be represented.
--------------------------------------------------------------------------- Suffix Decimal Constant Octal/Hexadecimal Constant --------------------------------------------------------------------------- none int int long int unsigned int long long int unsigned long int long long int unsigned long long int --------------------------------------------------------------------------- u or U unsigned int unsigned int unsigned long int unsigned long int unsigned long long int unsigned long long int --------------------------------------------------------------------------- l or L long int long int long long int unsigned long int long long int unsigned long long int --------------------------------------------------------------------------- Both u or U unsigned long int unsigned long int and l or L unsigned long long int unsigned long long int --------------------------------------------------------------------------- ll or LL long long int long long int unsigend long long int --------------------------------------------------------------------------- Both u or U unsigned long long int unsigned long long int and ll or LL ---------------------------------------------------------------------------
As for the prefix §6.4.4.1/3:
A decimal constant begins with a nonzero digit and consists of a sequence of decimal digits. An octal constant consists of the prefix 0 optionally followed by a sequence of the digits 0 through 7 only. A hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of the decimal digits and the letters a (or A) through f (or F) with values 10 through 15 respectively.

- 31,634
- 25
- 118
- 222
-
1FYI, I used a modified version of your table [here](http://stackoverflow.com/a/24148306/1708801). – Shafik Yaghmour Jun 10 '14 at 18:50
There are three types of integer literals(or integer constants in the standards terminology): decimal, octal or hex and the rule are slightly different for your specific example 6
would be int
but in general for decimal constants without a suffix(u, U, l, L, ll, LL) it will be based on which type can represent the value which is covered in the draft C99 standard section 6.4.4.1
Integer constants paragraph 5 which says:
The type of an integer literal is the first of the corresponding list in which its value can be represented.
so for a decimal literal without a suffix the types would be the first of:
- int
- long int
- long long int
and for octal and hex the types would be the first of:
- int
- unsigned int
- long int
- unsigned long int
- long long int
- unsigned long long int

- 154,301
- 39
- 440
- 740
-
-
-
-
@KerrekSB literal is C++ it comes under the integer constants section in C99. – Shafik Yaghmour Jan 27 '14 at 14:13
-
Sorry, my bad. I always think these questions are about C++ when in fact they are about C. Indeed, in C the only constants are literals, so that makes sense. – Kerrek SB Jan 27 '14 at 14:15
-
1Still, it might be wise to refer to them as _integer literals_, then everyone knows what you mean. "Constants" might mean a whole lot of different things in C, the term is simply not helpful. – Lundin Jan 27 '14 at 14:44