Skip to content

Instantly share code, notes, and snippets.

@tomchen
Created January 4, 2021 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomchen/9bb1d8492cd9e82289bd0c101cbad0d6 to your computer and use it in GitHub Desktop.
Save tomchen/9bb1d8492cd9e82289bd0c101cbad0d6 to your computer and use it in GitHub Desktop.
C Data Types

C Data Types

Type Explanation Minimum size (bytes) Minimum range Format specifier
char Smallest addressable unit of the machine that can contain basic character set. It is an integer type. Actual type can be either signed or unsigned. It contains CHAR_BIT bits. 1 [−127, +127] %c
signed char Of the same size as char, but guaranteed to be signed. 1 [−127, +127] %c (or %hhi for numerical output)
unsigned char Of the same size as char, but guaranteed to be unsigned. 1 [0, 255] %c (or %hhu for numerical output)
short
short int
signed short
signed short int
Short signed integer type. 2 [−32,767, 32,767] %hi or %hd
unsigned short
unsigned short int
Short unsigned integer type. 2 [0, 65,535] %hu
int
signed
signed int
Basic signed integer type. 2 [−32,767, 32,767] %i or %d
unsigned
unsigned int
Basic unsigned integer type. 2 [0, 65,535] %u
long
long int
signed long
signed long int
Long signed integer type. 4 [−2,147,483,647, 2,147,483,647] %li or %ld
unsigned long
unsigned long int
Long unsigned integer type. 4 [0, 4,294,967,295] %lu
long long
long long int
signed long long
signed long long int
Long long signed integer type. The range is specified since the C99 version of the standard. 8 [−9,223,372,036,854,775,807, 9,223,372,036,854,775,807] %lli or %lld
unsigned long long
unsigned long long int
Long long unsigned integer type. The range is specified since the C99 version of the standard. 8 [0, 18,446,744,073,709,551,615] %llu
float Real floating-point type, usually referred to as a single-precision floating-point type. 4 [3.4E +/- 38] (Converting from text:)
%f %F
%g %G
%e %E
%a %A
double Real floating-point type, usually referred to as a double-precision floating-point type. 8 [1.7E +/- 308] %lf %lF
%lg %lG
%le %lE
%la %lA
long double Real floating-point type, usually mapped to an extended precision floating-point number format. 16, 12 or 10 [3.4E +/- 4932] %Lf %LF
%Lg %LG
%Le %LE
%La %LA
  • float: Actual properties unspecified (except minimum limits); however, on most systems, this is the IEEE 754 single-precision binary floating-point format (32 bits). This format is required by the optional Annex F "IEC 60559 floating-point arithmetic".
  • double: Actual properties unspecified (except minimum limits); however, on most systems, this is the IEEE 754 double-precision binary floating-point format (64 bits). This format is required by the optional Annex F "IEC 60559 floating-point arithmetic".
  • long double: Actual properties unspecified. It can be either x86 extended-precision floating-point format (80 bits, but typically 96 bits or 128 bits in memory with padding bytes), the non-IEEE "double-double" (128 bits), IEEE 754 quadruple-precision floating-point format (128 bits), or the same as double. See the article on long double for details.
  • Whether it uses 32-bit or 64-bit (LP32, ILP32, LLP64, LP64) data model could decide the size and range of the data.
  • The range varies depending on the language and data model (e.g. [−127, +127] could be [−128, +127])

Reference: Wikipedia: C data types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment