Fixed width integer types (since C++11) (2024)

C++

Compiler support
Freestanding and hosted
Language
Standard library
Standard library headers
Named requirements
Feature test macros (C++20)
Language support library
Concepts library (C++20)
Metaprogramming library (C++11)
Diagnostics library
General utilities library
Strings library
Containers library
Iterators library
Ranges library (C++20)
Algorithms library
Numerics library
Localizations library
Input/output library
Filesystem library (C++17)
Regular expressions library (C++11)
Concurrency support library (C++11)
Technical specifications
Symbols index
External libraries

[edit]

Utilities library

Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions

is_constant_evaluated

(C++20)

is_within_lifetime

(C++26)

initializer_list

(C++11)

source_location

(C++20)

Debugging support

is_debugger_present

(C++26)

breakpoint_if_debugging

(C++26)

breakpoint

(C++26)

Three-way comparison

three_way_comparablethree_way_comparable_with

(C++20)(C++20)

strong_ordering

(C++20)

weak_ordering

(C++20)

partial_ordering

(C++20)

common_comparison_category

(C++20)

compare_three_way_result

(C++20)

compare_three_way

(C++20)

strong_order

(C++20)

weak_order

(C++20)

partial_order

(C++20)

compare_strong_order_fallback

(C++20)

compare_weak_order_fallback

(C++20)

compare_partial_order_fallback

(C++20)

is_eqis_ltis_lteq

(C++20)(C++20)(C++20)

is_neqis_gtis_gteq

(C++20)(C++20)(C++20)

General utilities
Date and time
Function objects
Formatting library (C++20)

bitset

hash

(C++11)

Relational operators (deprecated in C++20)

rel_ops::operator!=rel_ops::operator>

rel_ops::operator<=rel_ops::operator>=

Integer comparison functions

cmp_equalcmp_lesscmp_less_than

(C++20)(C++20)(C++20)

cmp_not_equalcmp_greatercmp_greater_than

(C++20)(C++20)(C++20)

in_range

(C++20)

Swap and type operations

swap

ranges::swap

(C++20)

exchange

(C++14)

declval

(C++11)

to_underlying

(C++23)

forward

(C++11)

forward_like

(C++23)

move

(C++11)

move_if_noexcept

(C++11)

as_const

(C++17)

Common vocabulary types

pair

tuple

(C++11)

optional

(C++17)

any

(C++17)

variant

(C++17)

tuple_size

(C++11)

tuple_element

(C++11)

apply

(C++17)

make_from_tuple

(C++17)

expected

(C++23)

Elementary string conversions

to_chars

(C++17)

from_chars

(C++17)

chars_format

(C++17)

to_chars_result

(C++17)

from_chars_result

(C++17)



[edit]

Type support

Basic types
Fixed width integer types (C++11)
Fixed width floating-point types (C++23)

ptrdiff_t

size_t

max_align_t

(C++11)

byte

(C++17)

nullptr_t

(C++11)

offsetof

NULL


Numeric limits

numeric_limits

C numeric limits interface
Runtime type information

type_info

type_index

(C++11)

bad_typeid

bad_cast

[edit]

Contents

  • 1 Types
  • 2 Macro constants
    • 2.1 Signed integers: minimum value
    • 2.2 Signed integers: maximum value
    • 2.3 Unsigned integers: maximum value
  • 3 Function macros for minimum-width integer constants
  • 4 Format macro constants
    • 4.1 Format constants for the std::fprintf family of functions
    • 4.2 Format constants for the std::fscanf family of functions
  • 5 Notes
  • 6 Example
  • 7 Defect reports
  • 8 References
  • 9 See also

[edit] Types

Defined in header <cstdint>

int8_tint16_tint32_tint64_t

(optional)

signed integer type with width of exactly 8, 16, 32 and 64 bits respectively
with no padding bits and using 2's complement for negative values
(provided if and only if the implementation directly supports the type)
(typedef) [edit]

int_fast8_tint_fast16_tint_fast32_tint_fast64_t

fastest signed integer type with width of at least 8, 16, 32 and 64 bits respectively
(typedef) [edit]

int_least8_tint_least16_tint_least32_tint_least64_t

smallest signed integer type with width of at least 8, 16, 32 and 64 bits respectively
(typedef) [edit]

intmax_t

maximum-width signed integer type
(typedef) [edit]

intptr_t

(optional)

signed integer type capable of holding a pointer to void
(typedef) [edit]

uint8_tuint16_tuint32_tuint64_t

(optional)

unsigned integer type with width of exactly 8, 16, 32 and 64 bits respectively
(provided if and only if the implementation directly supports the type)
(typedef) [edit]

uint_fast8_tuint_fast16_tuint_fast32_tuint_fast64_t

fastest unsigned integer type with width of at least 8, 16, 32 and 64 bits respectively
(typedef) [edit]

uint_least8_tuint_least16_tuint_least32_tuint_least64_t

smallest unsigned integer type with width of at least 8, 16, 32 and 64 bits respectively
(typedef) [edit]

uintmax_t

maximum-width unsigned integer type
(typedef) [edit]

uintptr_t

(optional)

unsigned integer type capable of holding a pointer to void
(typedef) [edit]

The implementation may define typedef names intN_t, int_fastN_t, int_leastN_t, uintN_t, uint_fastN_t, and uint_leastN_t when N is not 8, 16, 32 or 64. Typedef names of the form intN_t may only be defined if the implementation supports an integer type of that width with no padding. Thus, std::uint24_t denotes an unsigned integer type with a width of exactly 24 bits.

Each of the macros listed in below is defined if and only if the implementation defines the corresponding typedef name. The macros INTN_C and UINTN_C correspond to the typedef names int_leastN_t and uint_leastN_t, respectively.

[edit] Macro constants

Defined in header <cstdint>

Signed integers: minimum value

INT8_MININT16_MININT32_MININT64_MIN

(optional)

minimum value of std::int8_t, std::int16_t, std::int32_t and std::int64_t respectively
(macro constant) [edit]

INT_FAST8_MININT_FAST16_MININT_FAST32_MININT_FAST64_MIN

minimum value of std::int_fast8_t, std::int_fast16_t, std::int_fast32_t and std::int_fast64_t respectively
(macro constant) [edit]

INT_LEAST8_MININT_LEAST16_MININT_LEAST32_MININT_LEAST64_MIN

minimum value of std::int_least8_t, std::int_least16_t, std::int_least32_t and std::int_least64_t respectively
(macro constant) [edit]

INTPTR_MIN

(optional)

minimum value of std::intptr_t
(macro constant) [edit]

INTMAX_MIN

minimum value of std::intmax_t
(macro constant) [edit]
Signed integers: maximum value

INT8_MAXINT16_MAXINT32_MAXINT64_MAX

(optional)

maximum value of std::int8_t, std::int16_t, std::int32_t and std::int64_t respectively
(macro constant) [edit]

INT_FAST8_MAXINT_FAST16_MAXINT_FAST32_MAXINT_FAST64_MAX

maximum value of std::int_fast8_t, std::int_fast16_t, std::int_fast32_t and std::int_fast64_t respectively
(macro constant) [edit]

INT_LEAST8_MAXINT_LEAST16_MAXINT_LEAST32_MAXINT_LEAST64_MAX

maximum value of std::int_least8_t, std::int_least16_t, std::int_least32_t and std::int_least64_t respectively
(macro constant) [edit]

INTPTR_MAX

(optional)

maximum value of std::intptr_t
(macro constant) [edit]

INTMAX_MAX

maximum value of std::intmax_t
(macro constant) [edit]
Unsigned integers: maximum value

UINT8_MAXUINT16_MAXUINT32_MAXUINT64_MAX

(optional)

maximum value of std::uint8_t, std::uint16_t, std::uint32_t and std::uint64_t respectively
(macro constant) [edit]

UINT_FAST8_MAXUINT_FAST16_MAXUINT_FAST32_MAXUINT_FAST64_MAX

maximum value of std::uint_fast8_t, std::uint_fast16_t, std::uint_fast32_t and std::uint_fast64_t respectively
(macro constant) [edit]

UINT_LEAST8_MAXUINT_LEAST16_MAXUINT_LEAST32_MAXUINT_LEAST64_MAX

maximum value of std::uint_least8_t, std::uint_least16_t, std::uint_least32_t and std::uint_least64_t respectively
(macro constant) [edit]

UINTPTR_MAX

(optional)

maximum value of std::uintptr_t
(macro constant) [edit]

UINTMAX_MAX

maximum value of std::uintmax_t
(macro constant) [edit]

[edit] Function macros for minimum-width integer constants

INT8_CINT16_CINT32_CINT64_C

expands to an integer constant expression having the value specified by its argument and whose type is the promoted type of std::int_least8_t, std::int_least16_t, std::int_least32_t and std::int_least64_t respectively
(function macro) [edit]

INTMAX_C

expands to an integer constant expression having the value specified by its argument and the type std::intmax_t
(function macro) [edit]

UINT8_CUINT16_CUINT32_CUINT64_C

expands to an integer constant expression having the value specified by its argument and whose type is the promoted type of std::uint_least8_t, std::uint_least16_t, std::uint_least32_t and std::uint_least64_t respectively
(function macro) [edit]

UINTMAX_C

expands to an integer constant expression having the value specified by its argument and the type std::uintmax_t
(function macro) [edit]
#include <cstdint>UINT64_C(0x123) // expands to a literal of type uint_least64_t and value 0x123

[edit] Format macro constants

Defined in header <cinttypes>

[edit] Format constants for the std::fprintf family of functions

Each of the PRI macros listed here is defined if and only if the implementation defines the corresponding typedef name.

Equivalent
for int or
unsigned int
DescriptionMacros for data types

std::intx_t

std::int_leastx_t

std::int_fastx_t

std::intmax_t

std::intptr_t

doutput of a signed decimal integer valuePRIdxPRIdLEASTxPRIdFASTxPRIdMAXPRIdPTR
iPRIixPRIiLEASTxPRIiFASTxPRIiMAXPRIiPTR
uoutput of an unsigned decimal integer valuePRIuxPRIuLEASTxPRIuFASTxPRIuMAXPRIuPTR
ooutput of an unsigned octal integer valuePRIoxPRIoLEASTxPRIoFASTxPRIoMAXPRIoPTR
xoutput of an unsigned lowercase hexadecimal integer valuePRIxxPRIxLEASTxPRIxFASTxPRIxMAXPRIxPTR
Xoutput of an unsigned uppercase hexadecimal integer valuePRIXxPRIXLEASTxPRIXFASTxPRIXMAXPRIXPTR

[edit] Format constants for the std::fscanf family of functions

Each of the SCN macros listed in here is defined if and only if the implementation defines the corresponding typedef name and has a suitable std::fscanf length modifier for the type.

Equivalent
for int or
unsigned int
DescriptionMacros for data types

std::intx_t

std::int_leastx_t

std::int_fastx_t

std::intmax_t

std::intptr_t

dinput of a signed decimal integer valueSCNdxSCNdLEASTxSCNdFASTxSCNdMAXSCNdPTR
iinput of a signed integer valueSCNixSCNiLEASTxSCNiFASTxSCNiMAXSCNiPTR
uinput of an unsigned decimal integer valueSCNuxSCNuLEASTxSCNuFASTxSCNuMAXSCNuPTR
oinput of an unsigned octal integer valueSCNoxSCNoLEASTxSCNoFASTxSCNoMAXSCNoPTR
xinput of an unsigned hexadecimal integer valueSCNxxSCNxLEASTxSCNxFASTxSCNxMAXSCNxPTR

[edit] Notes

Because C++ interprets a character immediately following a string literal as a user-defined string literal, C code such as printf("%"PRId64"\n",n); is invalid C++ and requires a space before PRId64.

The C99 standard suggests that C++ implementations should not define the above limit, constant, or format macros unless the macros __STDC_LIMIT_MACROS, __STDC_CONSTANT_MACROS or __STDC_FORMAT_MACROS (respectively) are defined before including the relevant C header (stdint.h or inttypes.h). This recommendation was not adopted by any C++ standard and was removed in C11. However, some implementations (such as glibc 2.17) try to apply this rule, and it may be necessary to define the __STDC macros; C++ compilers may try to work around this by automatically defining them in some circ*mstances.

std::int8_t may be signed char and std::uint8_t may be unsigned char, but neither can be char regardless of its signedness (because char is not considered a "signed integer type" or "unsigned integer type").

[edit] Example

See also a note regarding spaces before format macros used in this example.

Run this code

#include <cinttypes>#include <cstdio>int main(){ std::printf("%zu\n", sizeof(std::int64_t)); std::printf("%s\n", PRId64); std::printf("%+" PRId64 "\n", INT64_MIN); std::printf("%+" PRId64 "\n", INT64_MAX); std::int64_t n = 7; std::printf("%+" PRId64 "\n", n);}

Possible output:

8lld-9223372036854775808+9223372036854775807+7

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 2820C++11the requirements for optional typedef names and macros were inconsistent with Cmade consistent

[edit] References

  • C++23 standard (ISO/IEC 14882:2024):
  • 17.4.1 Header <cstdint> synopsis [cstdint.syn]
  • 31.13.2 Header <cinttypes> synopsis [cinttypes.syn]
  • C++20 standard (ISO/IEC 14882:2020):
  • 17.4 Integer types [cstdint]
  • 29.12.2 Header <cinttypes> synopsis [cinttypes.syn]
  • C++17 standard (ISO/IEC 14882:2017):
  • 21.4 Integer types [cstdint]
  • 30.11.2 Header <cinttypes> synopsis [cinttypes.syn]
  • C++14 standard (ISO/IEC 14882:2014):
  • 18.4 Integer types [cstdint]
  • 27.9.2 C library files [c.files]
  • C++11 standard (ISO/IEC 14882:2011):
  • 18.4 Integer types [cstdint]
  • 27.9.2 C library files [c.files]

[edit] See also

  • Fundamental types

C documentation for Fixed width integer types

Fixed width integer types (since C++11) (2024)

FAQs

What are fixed width integer types? ›

Fixed-width integers are integral types with a fixed number of bits. The C++ standard only specifies a minimum byte count for types such as short , int and long . Fixed-width integers guarantee a specific size, but their use can have an impact on portability, since they are not supported by all platforms.

What are the data types in C++ 11? ›

In C++, there are five basic data types: int, float, char, bool, and double. Integers, floating-point numbers, characters, Boolean values, & double-precision floating-point numbers are each represented by one of these data types.

What is the type of integer in C++? ›

C++ int. The int keyword is used to indicate integers. Its size is usually 4 bytes. Meaning, it can store values from -2147483648 to 2147483647.

What is the width of integer in C? ›

The integer is, normally, the natural size for any processor or machine. In the table mentioned above, the integer is 16-bit or 2 bytes wide. Thus, the compiler is also 16-bit or 2 bytes wide. If the compiler was 32-bit wide, the int type size would have been about 32-bits or 4 bytes.

What are the 4 integer data types? ›

Integers: These are of four types: byte , short , int , long . It is important to note that these are signed positive and negative values. Signed integers are stored in a computer using 2's complement.

What are all C integer types? ›

Integer Data Types in C
TypeStorage sizeValue range
short2 bytes-32,768 to 32,767
unsigned short2 bytes0 to 65,535
long8 bytes-9223372036854775808 to 9223372036854775807
unsigned long8 bytes0 to 18446744073709551615
5 more rows

What is the C ++ 11 standard? ›

C++11 standard introduces the ability to initialize class objects by rvalues, to write clear, concise, and efficient code. This means that temporaries are now initialized directly from the entire rvalue object, instead of calling a constructor to copy the object into the temporary.

What is the difference between C ++ 11 and C++ 03? ›

However, C++03 allows initializer-lists only on structs and classes that conform to the Plain Old Data (POD) definition; C++11 extends initializer-lists, so they can be used for all classes including standard containers like std::vector .

What is the longest integer data type in C++? ›

unsigned long long int is the biggest datatype in c++. Its 8 byte in size. If you need more range then you can implement a class just like BigInt class in JAVA.

What is the size of an integer in C++? ›

Integer: The keyword used for integer data types is int. Integers typically require 4 bytes of memory space and range from -2147483648 to 2147483647.

What are integer types? ›

Integers come in three types: Zero (0) Positive Integers (Natural numbers) Negative Integers (Additive inverse of Natural Numbers)

What is the type of integer literal in C++? ›

Integer literals begin with a digit and have no fractional parts or exponents. You can specify integer literals in decimal, binary, octal, or hexadecimal form. You can optionally specify an integer literal as unsigned, and as a long or long long type, by using a suffix.

What is the width of an int in C++? ›

Properties
Type specifierEquivalent typeWidth in bits by data model
C++ standard
intintat least 16
signed
signed int
22 more rows
Aug 13, 2024

What is the integer data type in C? ›

An integer type variable can store zero, positive, and negative values without any decimal. In C language, the integer data type is represented by the 'int' keyword, and it can be both signed or unsigned. By default, the value assigned to an integer variable is considered positive if it is unsigned.

What is an integer type in Ada? ›

In Ada, an integer type is not specified in terms of its machine representation, but rather by its range. The compiler will then choose the most appropriate representation. Another point to note in the above example is the My_Int'Image (I) expression.

What are examples of integer data types? ›

Integer data types are used to store a whole number without decimals, like 35, -50, or 1345000. The integer data type has two categories: Signed integers - can store both positive and negative values. Unsigned integers - can only store non-negative values.

What are the 4 types of integer data type in Python? ›

For instance, Python has several built-in data types, including numeric types (int, float, complex), string (str), boolean (bool), and collection types (list, tuple, dict, set).

What are the three types of integer representation? ›

The commonly-used bit-lengths for integers are 8-bit, 16-bit, 32-bit or 64-bit. Besides bit-lengths, there are two representation schemes for integers: Unsigned Integers: can represent zero and positive integers. Signed Integers: can represent zero, positive and negative integers.

References

Top Articles
Long Walks on the Beach Aren't the Only Way to Navigate Rio de Janeiro
Butler Soy Curls Review and Recipes: Buffalo Soy Curls
Pau.blaz
サリスF70プッシュへのプッシュフルエクステンションヘビーデューティドロワーランナー
Dive Bars With Pool Tables Near Me
Diego Balleza Lpsg
Frank 26 Forum
80 For Brady Showtimes Near Cinemark At Harlingen
Schluter & Balik Funeral Home Obituaries
Costco Gas Price Carlsbad
Survivor Australia Wiki
Giant Egg Classic Wow
Mcdonalds 5$
Rick Harrison Daughter Ciana
They Cloned Tyrone Showtimes Near Showbiz Cinemas - Kingwood
Joann Ally Employee Portal
Bank Of America Operating Hours Today
Strange World Showtimes Near Cmx Downtown At The Gardens 16
Wmlink/Sspr
Apple Store Near Me Make Appointment
Central Nj Craiglist
Shoulder Ride Deviantart
Top Football Recruits 2017
Somewhere In Queens Showtimes Near The Maple Theater
Vegamovies 2023 » Career Flyes
Ksat Doppler Radar
Joy Ride 2023 Showtimes Near Amc Ward Parkway
Solar Smash Secret Achievements List 2023
Hahs Sentral
Haktuts.in Coin Master 50 Spin Link
Week 8 – Quarter 1 Matatag DLL Daily Lesson Logs | September 16 – 20, 2024 DLL
Greatpeople.me Login Schedule
South Bend Tribune Online
How To Pause Tamagotchi Gen 2
Restored Republic June 16 2023
4201 Crossroads Wy, Rancho Cordova, CA 95742 - MLS 224103058 - Coldwell Banker
Operation Fortune Showtimes Near Century Rio 24
Official Klj
Bella Isabella 1425
France 2 Journal Télévisé 20H
Current Students - Pace University Online
charleston rooms & shares - craigslist
Lacy Aaron Schmidt Where Is He Now
Surface Area Formulas (video lessons, examples, step-by-step solutions)
Hercules 2014 Full Movie Youtube
Oge Number
Meshuggah Bleed Tab
'It's huge': Will Louisville's Logan Street be the next Findlay or Pike Place market?
Busted Newspaper Lynchburg County VA Mugshots
Smokey's 35Th Halsted
Cnas Breadth Requirements
Texas State Final Grades
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 5358

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.