Namespaces
Variants
Views
Actions

integer literal

From cppreference.com
< cpp‎ | language
Revision as of 19:04, 31 May 2013 by P12bot (Talk | contribs)

 
 
C++ language
General topics
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)
Initialization
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

Syntax

[0-9]+ type_suffix (1)
0[0-7]+ type_suffix (2)
0x[0-9a-f]+ type_suffix (3)
0b[0-1]+ type_suffix (4) (since C++14)

Explanation

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

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
User defined (since C++11)
anything

Notes

  • Letters in integer constants are case-insensitive.

Example

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

Output:

123
83
291
2
12345678901234567890
4294967295
18446744073709551615

(output from an x86_64 processor)