C data types explained

In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations or variables. Data types also determine the types of operations or methods of processing of data elements.

The C language provides basic arithmetic types, such as integer and real number types, and syntax to build array and compound types. The C standard library contains additional definitions of support types, that have additional properties, such as providing storage with an exact size, independent of the language implementation on specific hardware platforms.[1] [2]

Primary types

Main types

The C language provides the four basic arithmetic type specifiers,, and (as well as the Boolean type), and the modifiers,,, and . The following table lists the permissible combinations in specifying a large set of storage size-specific declarations.

The actual size of the integer types varies by implementation. The standard requires only size relations between the data types and minimum sizes for each data type:

The relation requirements are that the is not smaller than, which is not smaller than, which is not smaller than . As 's size is always the minimum supported data type, no other data types (except bit-fields) can be smaller.

The minimum size for is 8 bits, the minimum size for and is 16 bits, for it is 32 bits and must contain at least 64 bits.

The type should be the integer type that the target processor is most efficiently working with. This allows great flexibility: for example, all types can be 64-bit. However, several different integer width schemes (data models) are popular. Because the data model defines how different programs communicate, a uniform data model is used within a given operating system application interface.[7]

In practice, is usually 8 bits in size and is usually 16 bits in size (as are their unsigned counterparts). This holds true for platforms as diverse as 1990s SunOS 4 Unix, Microsoft MS-DOS, modern Linux, and Microchip MCC18 for embedded 8-bit PIC microcontrollers. POSIX requires to be exactly 8 bits in size.[8] [9]

Various rules in the C standard make the basic type used for arrays suitable to store arbitrary non-bit-field objects: its lack of padding bits and trap representations, the definition of object representation,[5] and the possibility of aliasing.[10]

The actual size and behavior of floating-point types also vary by implementation. The only requirement is that is not smaller than, which is not smaller than . Usually, the 32-bit and 64-bit IEEE 754 binary floating-point formats are used for and respectively.

The C99 standard includes new real floating-point types and, defined in [[C_mathematical_functions|<math.h>]]. They correspond to the types used for the intermediate results of floating-point expressions when is 0, 1, or 2. These types may be wider than .

C99 also added complex types:,, . C11 added imaginary types (which were described in an informative annex of C99):,, . Including the header <complex.h> allows all these types to be accessed with using and respectively.

Boolean type

C99 added a Boolean data type . Additionally, the <stdbool.h> header defines as a convenient alias for this type, and also provides macros for true and false. functions similarly to a normal integer type, with one exception: any conversion to a gives 0 (false) if the value equals 0; otherwise, it gives 1 (true). This behavior exists to avoid integer overflows in implicit narrowing conversions. For example, in the following code:

unsigned char b = 256;

if (b)

Variable b evaluates to false if has a size of 8 bits. This is because the value 256 does not fit in the data type, which results in the lower 8 bits of it being used, resulting in a zero value. However, changing the type causes the previous code to behave normally:

_Bool b = 256;

if (b)

The type also ensures true values always compare equal to each other:

_Bool a = 1;_Bool b = 2;

if (a

b)

In C23, (and its values true and false) became a core functionality of the language (making the contents of <stdbool.h> obsolescent[11] [12]), allowing for the following examples of code:

bool b = true;

if (b)

Bit-precise integer types

Since C23, the language allows the programmer to define integers that have a width of an arbitrary number of bits. Those types are specified as, where N is an integer constant expression that denotes the number of bits, including the sign bit for signed types, represented in two's complement. The maximum value of N is provided by BITINT_MAXWIDTH and is at least ULLONG_WIDTH. Therefore, the type (or) takes values from −2 to 1 while takes values from 0 to 3. The type also exists, being either 0 or 1 and has no equivalent signed type.[13] A proposal for C2Y proposes to lift this restriction and allow which then has the possible values 0 and -1, removing the special case for .[14]

Size and pointer difference types

The C language specification includes the s and to represent memory-related quantities. Their size is defined according to the target processor's arithmetic capabilities, not the memory capabilities, such as available address space. Both of these types are defined in the <stddef.h> header.

is an unsigned integer type used to represent the size of any object (including arrays) in the particular implementation. The operator yields a value of the type . The maximum size of is provided via SIZE_MAX, a macro constant which is defined in the <[[#Fixed-width integer types|stdint.h]]> header. is guaranteed to be at least 16 bits wide. Additionally, POSIX includes, which is a signed integer type of the same width as .

is a signed integer type used to represent the difference between pointers. It is guaranteed to be valid only against pointers of the same type; subtraction of pointers consisting of different types is implementation-defined.

Interface to the properties of the basic types

Information about the actual properties, such as size, of the basic arithmetic types, is provided via macro constants in two headers: <limits.h> header defines macros for integer types and <float.h> header defines macros for floating-point types. The actual values depend on the implementation.

Properties of integer types

Properties of floating-point types

Fixed-width integer types

The C99 standard includes definitions of several new integer types to enhance the portability of programs.[2] The already available basic integer types were deemed insufficient, because their actual sizes are implementation defined and may vary across different systems. The new types are especially useful in embedded environments where hardware usually supports only several types and that support varies between different environments. All new types are defined in <inttypes.h> header and also are available at <stdint.h> header. The types can be grouped into the following categories:

The following table summarizes the types and the interface to acquire the implementation details (n refers to the number of bits):

Type categorySigned typesUnsigned types
TypeMinimum valueMaximum valueTypeMinimum valueMaximum value
Exact widthint''n''_t INT''n''_MIN INT''n''_MAXuint''n''_t 0 UINT''n''_MAX
Least widthint_least''n''_t INT_LEAST''n''_MIN INT_LEAST''n''_MAXuint_least''n''_t 0 UINT_LEAST''n''_MAX
Fastestint_fast''n''_t INT_FAST''n''_MIN INT_FAST''n''_MAXuint_fast''n''_t 0 UINT_FAST''n''_MAX
Pointerintptr_t INTPTR_MIN INTPTR_MAXuintptr_t 0 UINTPTR_MAX
Maximum widthintmax_t INTMAX_MIN INTMAX_MAXuintmax_t 0 UINTMAX_MAX

Printf and scanf format specifiers

See main article: printf format string and scanf format string.

The <inttypes.h> header provides features that enhance the functionality of the types defined in the <stdint.h> header. It defines macros for printf format string and scanf format string specifiers corresponding to the types defined in <stdint.h> and several functions for working with the intmax_t and uintmax_t types. This header was added in C99.

format string

The macros are in the format PRI''{fmt}{type}''. Here defines the output formatting and is one of d (decimal), x (hexadecimal), o (octal), u (unsigned) and i (integer). defines the type of the argument and is one of ''n'', FAST''n'', LEAST''n'', PTR, MAX, where ''n'' corresponds to the number of bits in the argument.

format string

The macros are in the format SCN''{fmt}{type}''. Here defines the output formatting and is one of d (decimal), x (hexadecimal), o (octal), u (unsigned) and i (integer). defines the type of the argument and is one of ''n'', FAST''n'', LEAST''n'', PTR, MAX, where ''n'' corresponds to the number of bits in the argument.

Functions

Additional floating-point types

Similarly to the fixed-width integer types, ISO/IEC TS 18661 specifies floating-point types for IEEE 754 interchange and extended formats in binary and decimal:

Pointers

Every data type T has a corresponding type pointer-to-T. A pointer is a data type that contains the address of a storage location of a variable of a particular type. They are declared with the asterisk (*) type declarator following the basic storage type and preceding the variable name. Whitespace before or after the asterisk is optional.char *p;long *q;int *r;

Pointers may also be declared for pointer data types, thus creating multiple indirect pointers, such as and, including pointers to array types. The latter are less common than an array of pointers, and their syntax may be confusing:char *pc[10]; // array of 10 elements of 'pointer to char'char (*pa)[10]; // pointer to a 10-element array of char

The element pc requires ten blocks of memory of the size of pointer-to-char (usually 40 or 80 bytes on common platforms), but element pa is only one pointer (size 4 or 8 bytes), and the data it refers to is an array of ten bytes .

C also has a "pointer-to-void", void *.[15] The name "pointer-to-void" does not imply it points to void memory (as void is an incomplete type with no size), but rather that it points to something of unspecified type. It must be converted to another pointer type before it can be dereferenced. A void * may not point to a function. A call to malloc returns void *, and free takes a void *.

C uses the concept of a null pointer to denote a pointer that does not refer to any valid data. The macro NULL is often used in place of a null pointer, relying on implicit type conversion when possible. However, this usage can be problematic and may be a source of programming errors. In particular, the expansion of NULL may have a pointer type or an integer type, depending on the implementation. C23 introduced the predefined constant nullptr and its type nullptr_t (which has the single value nullptr) to express a null pointer constant. nullptr is unambiguously a pointer, and may convert to any object or function pointer, and allows a specific nullptr_t case in _Generic.[16] The size and alignment of this type is the same as for a pointer to character type (or void *), but other pointer types may still have a different size and alignment; thus not all null pointers are replaceable with nullptr.[17]

Arrays

See also: Array (data type). For every type T, except void and function types, there exist the types "array of N elements of type T". An array is a collection of values, all of the same type, stored contiguously in memory. An array of size N is indexed by integers from 0 up to and including ''N'' − 1. Here is a brief example:

int a[10]; // array of 10 elements, each of type int

Arrays can be initialized with a compound initializer, but not assigned. Arrays are passed to functions by passing a pointer to the first element. Multidimensional arrays are defined as "array of array ...", and all except the outermost dimension must have compile-time constant size:

int aa[10][8]; // array of 10 elements, each of type 'array of 8 int elements'

In C, a string is often stored as an array of char (char[]), but this is distinct from a pointer-to-char (char *). char[] cannot be reassigned, and lives where it is defined, while char * is reassignable, but cannot be modified.char s[] = "Hello, world!";char *p = s; // s decays to &s[0], p points to the first characterEven if a function takes T[] as a parameter, it decays into a T * which points to its first element.void f(int a[]);

// this is the same as:void f(int *a);

Indexing an array is defined in terms of pointer arithmetic, that is, a[i] is equivalent to *(a + i).[18]

Enums

See main article: Enumerated type. In C, an enum is an integer type whose values are restricted to a set of named constants.[19] Enums cannot be forward-declared. Enums may also directly be assigned values, and are commonly used with switch to enumerate multiple cases.

  1. include

enum Status ;

const char *get_status_string(enum Status status) Enum constants are known at compile time, and are often a safer means to define integral constants than macros. An enum's underlying size is usually int, but since C23 an enum's underlying size can be directly specified to be any integral type.enum Color : char ;

Because enums are not type-safe, they can be assigned a value of another enum. Enums also need not be assigned values necessarily within the range of defined values.enum Color color = YELLOW; // YELLOW = 3enum Month month = JUNE; // JUNE = 6

color = month; // color is now 6 (INDIGO)month = 999; // there may not be a value of 999 in enum Month, but still allowed

Structs

See main article: struct (C programming language). Structures (structs) aggregate the storage of multiple data items, of potentially differing data types, into one contiguous memory block referenced by a single variable. Members may possibly be padded for memory alignment, and thus it is often recommended to order fields from largest to smallest size for efficient memory usage.

struct Student ;

// Positional initialization - values matches field orderstruct Student alice = ;// Designated initializer (since C99)struct Student bob = ;

Structs may also use bit fields to allow fields to share the same storage units, but layouts are implementation-defined.struct Properties ;

The memory layout of a struct is a language implementation issue for each platform, with a few restrictions. The memory address of the first member must be the same as the address of structure itself. Structs may be initialized or assigned to using compound literals. A function may directly return a struct, although this is often not efficient at run-time. Since C99, a struct may also end with a flexible array member.

Functions may take a struct as a parameter by value, but this is expensive as it copies the entire struct. Meanwhile, passing it by pointer is often preferable as the size of a pointer is known (typically 4 or 8 bytes).

  1. include

// passing by valuevoid print_student(struct Student s)

// passing by pointervoid print_student(struct Student *s)

Structs can be composed of other structs:struct Date ;

struct Birthday ;

A struct containing a pointer to a struct of its own type is commonly used to build linked data structures:struct LinkedList ;

Unions

A union type is a special construct that permits access to the same memory block by using a choice of differing type descriptions.// holds either an integer or floating point valueunion Number d;

d.i = 10; // d now holds 10d.f = 3.14f; // d now holds 3.14, overwriting 10

In the following example, a union of data types may be declared to permit reading the same data either as an integer, a float, or any other user declared type:union u;The total size of u is the size of u.s – which happens to be the sum of the sizes of u.s.u and u.s.d – since s is larger than both i and f. When assigning something to u.i, some parts of u.f may be preserved if u.i is smaller than u.f.

Reading from a union member is not the same as casting since the value of the member is not converted, but merely read.

Function pointers

Function pointers allow referencing functions with a particular signature. For example, to store the address of the standard function abs in the variable my_int_f:

int (*my_int_f)(int) = &abs;// the & operator can be omitted, but makes clear that the "address of" abs is used here

Function pointers are invoked by name just like normal function calls.

  1. include
  2. include

int (*my_abs)(int) = &abs;int x = -42;int abs_of_x = my_abs(x);printf("abs(%d) = %d\n", x, abs_of_x);

Type qualifiers

See main article: Type qualifier.

The aforementioned types can be characterized further by type qualifiers, yielding a qualified type. and C11, there are four type qualifiers in standard C:

Of these, const is by far the best-known and most used, appearing in the C standard library and encountered in any significant use of the C language, which must satisfy const-correctness. The other qualifiers are primarily used for low-level programming: volatile is intended suppress compiler optimisations on a variable by suggesting it may change at any time, restrict indicates that the object pointed to by a pointer is accessed only by that pointer, and _Atomic indicates that the object is "atomic", i.e. reads and writes are indivisible.

See also

Notes and References

  1. Web site: Portable Fixed-Width Integers in C. Barr. Michael. 2 December 2007. 18 January 2016.
  2. Book: ISO/IEC 9899:1999 specification, TC3 . p. 255, § 7.18 Integer types .
  3. Web site: Arithmetic types. cppreference.com. 15 September 2025.
  4. Web site: C and C++ Integer Limits . 21 July 2023 .
  5. Book: ISO/IEC 9899:1999 specification, TC3 . p. 37, § 6.2.6.1 Representations of types – General.
  6. Book: ISO/IEC 9899:1999 specification, TC3 . p. 22, § 5.2.4.2.1 Sizes of integer types .
  7. Web site: 64-Bit Programming Models: Why LP64? . The Open Group . 9 November 2011.
  8. Web site: Width of Type (The GNU C Library) . 2022-07-30 . www.gnu.org.
  9. Web site: . 2022-07-30 . pubs.opengroup.org.
  10. Book: ISO/IEC 9899:1999 specification, TC3 . p. 67, § 6.5 Expressions.
  11. Web site: . pubs.opengroup.org. The IEEE and The Open Group. IEEE Std 1003.1-2024. 2024.
  12. Web site: Standard library header . cppreference.com. cppreference.com. cppreference.com. 7 February 2026.
  13. Book: ISO/IEC 9899:2023 specification draft. p. 37, § 6.2.5 Types.
  14. Book: Integer Sets, v3, WG14 N 3699. p. 6, § 1.2 Bit-precise Integers.
  15. Book: ISO/IEC 9899:1999 specification, TC3 . p. 47, § 6.3.2.3 Pointers.
  16. Web site: nullptr_t. cppreference.com. cppreference.com. cppreference.com. 7 February 2026.
  17. Web site: WR14-N3042: Introduce the nullptr constant . open-std.org . https://web.archive.org/web/20221224043228/https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm . December 24, 2022 . 2022-07-22 . live.
  18. Book: Plauger, P J . ANSI and ISO Standard C Programmer's Reference . P. J. Plauger . Brodie, Jim . 1992 . Microsoft Press . Redmond, WA . 978-1-55615-359-4 . 108 . registration .
  19. Web site: Enumerations. cppreference.com. cppreference.com. cppreference.com. 7 February 2026.
  20. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3631.pdf C11:The New C Standard