Namespaces
Variants
Views
Actions

integer literal

From cppreference.com
 
 
C++ language
General topics
Preprocessor
Comments
Keywords
ASCII chart
Escape sequences
History of C++
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

Contents

[edit] Syntax

[0-9]+ type_suffix (1)
0 [0-7]+ type_suffix (2)
0 x [0-9a-b]+ type_suffix (3)

[edit] Explanation

  1. Decimal notation
  2. Octal notation
  3. Hexadecimal notation

[edit] Types by suffix

(no suffix)
int
u
unsigned int
l
long
ul
unsigned long
ll (since C++11)
long long
ull (since C++11)
unsigned long long

[edit] Notes

  • Letters in integer constants are case-insensitive.

[edit] Example

std::cout << 123    << '\n'
          << 0123   << '\n'
          << 0x123  << '\n'
          << 12345678901234567890UL << '\n'
          << -1u    << '\n'
          << -1ull  << '\n';

Output:

123
83
291
12345678901234567890
4294967295
18446744073709551615

(output from an x86_64 processor)