c/language/type

(See also for the details on most built-in types and  the list of type-related utilities that are provided by the C library)

,, and have a property called type, which determines the interpretation of the binary value stored in an object or evaluated by the expression.

Type classification
The C type system consists of the following types:


 * the type
 * basic types
 * the type
 * signed integer types
 * standard:, , ,


 * unsigned integer types
 * standard:, , ,


 * floating-point types
 * real floating-point types:, ,




 * derived types

For every type listed above several qualified versions of its type may exist, corresponding to the combinations of one, two, or all three of the, , and qualifiers (where allowed by the qualifier's semantics).

Type groups

 * object types: all types that aren't function types
 * character types:, ,
 * integer types:, signed integer types, unsigned integer types, enumerated types
 * real types: integer types and real floating types
 * : integer types and floating types
 * scalar types: arithmetic types, pointer types
 * aggregate types: array types and structure types
 * derived declarator types: array types, function types, and pointer types

Constructing a complete object type such that the number of bytes in its object representation is not representable in the type size_t (i.e. the result type of operator) is undefined behavior.

Compatible types
In a C program, the declarations referring to the same object or function in different translation units do not have to use the same type. They only have to use sufficiently similar types, formally known as compatible types. Same applies to function calls and lvalue accesses; argument types must be compatible with parameter types and lvalue expression type must be compatible with the object type that is accessed.

The types and  are compatible, if
 * they are the same type (same name or aliases introduced by a )
 * they are identically cvr-qualified versions of compatible unqualified types
 * they are pointer types and are pointing to compatible types
 * they are array types, and
 * their element types are compatible, and
 * if both have constant size, that size is the same. Note: arrays of unknown bound are compatible with any array of compatible element type.


 * they are both structure/union/enumeration types, and
 * if one is declared with a tag, the other must also be declared with the same tag.
 * if both are completed types, their members must correspond exactly in number, be declared with compatible types, and have matching names.
 * additionally, if they are enumerations, corresponding members must also have the same values.
 * additionally, if they are structures or unions,
 * Corresponding members must be declared in the same order (structures only)
 * Corresponding must have the same widths.


 * one is an enumerated type and the other is that enumeration's underlying type
 * they are function types, and
 * their return types are compatible
 * they both use parameter lists, the number of parameters (including the use of the ellipsis) is the same, and the corresponding parameter, after applying array-to-pointer and function-to-pointer type adjustments and after stripping top-level qualifiers, have compatible types
 * one is an old-style (parameter-less) definition, the other has a parameter list, the parameter list does not use an ellipsis and each parameter is compatible (after function parameter type adjustment) with the corresponding old-style parameter after default argument promotions
 * one is an old-style (parameter-less) declaration, the other has a parameter list, the parameter list does not use an ellipsis, and all parameters (after function parameter type adjustment) are unaffected by default argument promotions

The type is not compatible with  and not compatible with.

If two declarations refer to the same object or function and do not use compatible types, the behavior of the program is undefined.

Note: C++ has no concept of compatible types. A C program that declares two types that are compatible but not identical in different translation units is not a valid C++ program.

Composite types
A composite type can be constructed from two types that are compatible; it is a type that is compatible with both of the two types and satisfies the following conditions:
 * If both types are array types, the following rules are applied:
 * If one type is an array of known constant size, the composite type is an array of that size.


 * Otherwise, both types are arrays of unknown size and the composite type is an array of unknown size.
 * The element type of the composite type is the composite type of the two element types.

These rules apply recursively to the types from which the two types are derived.
 * If only one type is a function type with a parameter type list (a function prototype), the composite type is a function prototype with the parameter type list.
 * If both types are function types with parameter type lists, the type of each parameter in the composite parameter type list is the composite type of the corresponding parameters.

For an identifier with internal or external declared in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the type of the identifier at the later declaration becomes the composite type.

Incomplete types
An incomplete type is an object type that lacks sufficient information to determine the size of the objects of that type. An incomplete type may be completed at some point in the translation unit.

The following types are incomplete:
 * the type . This type cannot be completed.
 * array type of unknown size. It can be completed by a later declaration that specifies the size.


 * structure or union type of unknown content. It can be completed by a declaration of the same structure or union that defines its content later in the same scope.

Type names
A type may have to be named in context other than the. In these situations, type name is used, which is, grammatically, exactly the same as a list of type-specifiers and type-qualifiers, followed by the declarator (see ) as would be used to declare a single object or function of this type, except that the identifier is omitted:

Except the redundant parentheses around the identifier are meaningful in a type-name and represent "function with no parameter specification":

Type names are used in the following situations:

A type name may introduce a new type: