# integer constant

< c‎ | language

C
 Language Headers Type support Program utilities Variadic function support Error handling Dynamic memory management Date and time utilities Strings library Algorithms Numerics Input/output support Localization support Atomic operations (C11) Thread support (C11) Technical Specifications

C language
 Basic concepts Keywords Preprocessor Statements Expressions Initialization Declarations Functions Miscellaneous History of C Technical Specifications

Allows values of integer type to be used in expressions directly.

## Contents

### Syntax

An integer constant is a non-lvalue expression of the form

 decimal-constant integer-suffix(optional) (1) octal-constant integer-suffix(optional) (2) hex-constant integer-suffix(optional) (3)

where

• decimal-constant is a non-zero decimal digit (1, 2, 3, 4, 5, 6, 7, 8, 9), followed by zero or more decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
• octal-constant is the digit zero (0) followed by zero or more octal digits (0, 1, 2, 3, 4, 5, 6, 7)
• hex-constant is the character sequence 0x or the character sequence 0X followed by one or more hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, A, b, B, c, C, d, D, e, E, f, F)
• integer-suffix, if provided, may contain one or both of the following (if both are provided, they may appear in any order:
• unsigned-suffix (the character u or the character U)
• long-suffix (the character l or the character L) or the long-long-suffix (the character sequence ll or the character sequence LL) (since C99)

### Explanation

1) Decimal integer constant (base 10, the first digit is the most significant).
2) Octal integer constant (base 8, the first digit is the most significant).
3) Hexadecimal integer constant (base 16, the first digit is the most significant, the letters 'a' through 'f' represent the decimal values 10 through 15).

The following variables are initialized to the same value:

int d = 42;
int o = 052;
int x = 0x2a;
int X = 0X2A;

### The type of the integer constant

The type of the integer constant is the first type in which the value can fit, from the list of types which depends on which numeric base and which integer-suffix was used.

Types allowed for integer constants
suffix decimal bases hexadecimal or octal bases
no suffix int

long int
unsigned long int (until C99)
long long int (since C99)

int

unsigned int
long int
unsigned long int
long long int(since C99)
unsigned long long int(since C99)

u or U unsigned int

unsigned long int
unsigned long long int(since C99)

unsigned int

unsigned long int
unsigned long long int(since C99)

l or L long int

unsigned long int(until C99)
long long int(since C99)

long int

unsigned long int
long long int(since C99)
unsigned long long int(since C99)

both l/L and u/U unsigned long int

unsigned long long int(since C99)

unsigned long int

unsigned long long int(since C99)

ll or LL long long int(since C99) long long int(since C99)

unsigned long long int(since C99)

both ll/LL and u/U unsigned long long int(since C99) unsigned long long int(since C99)

If the value of the integer constant is too big to fit in any of the types allowed by suffix/base combination and the compiler supports extended integer types (such as __int128), the constant may be given the extended integer type; otherwise, the program is ill-formed.