C - Data Type Integer Literal


Because there are different types of integer variables, you can create different kinds of integer constants.

The integer value 100 will be of type int.

To make it type long, append an uppercase or lowercase letter L to the numeric value.

100 as a long value is written as 100L.

To declare and initialize the variable myValue of long type, you could write this:

long myValue = 1287600L;

You write negative integer constants with a minus sign, for example:

int decrease = -4;
long myValue = -100000L;

You specify integer constants to be of type long long by appending two Ls:

long long really_big_number = 123456789LL;

To specify a constant to be of an unsigned type, you append a U, as in these examples:

unsigned int count = 100U;
unsigned long value = 999999999UL;

To store integers with the largest magnitude, you could define a variable like this:

unsigned long long metersPerLightYear = 9460730472580800ULL;

The ULL specifies that the initial value is type unsigned long long.

Related Topics