| Name | Description | Notes | Source | Availability | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
char |
Specifier for integer types | L | Q | Keyword | C89 | C90 | C95 | C99 | C11 | ||
double |
Specifier for floating-point types | L | Q | Keyword | C89 | C90 | C95 | C99 | C11 | ||
float |
Specifier for floating-point types | L | Q | Keyword | C89 | C90 | C95 | C99 | C11 | ||
int |
Specifier for integer types | L | Q | Keyword | C89 | C90 | C95 | C99 | C11 | ||
long |
Specifier for integer and floating-point types | L | Q | Keyword | C89 | C90 | C95 | C99 | C11 | ||
short |
Specifier for integer types | L | Q | Keyword | C89 | C90 | C95 | C99 | C11 | ||
void |
Specifier for empty type, generic pointer type and empty parameter list | L | Q | Keyword | C89 | C90 | C95 | C99 | C11 | ||
In C, a type denotes a set of distinct interchangable values. Every object has a type, indicating the set of possible values it can hold. Every expression has a type, determined by the types of the primitive expressions it is made from, and the operators that combine them. C has several native types and several ways to construct new types.
The native types are identified by combinations of the following keywords:
- type-specifier
voidcharshortintlongfloatdoublesignedunsigned-
_Boolsince C99 -
_Complexsince C99 -
_Imaginarysince C99
From these are built the basic types, which include the integer types and the floating-point types:
_Boolchardoubledouble _Complexfloatfloat _Complexintlonglong doublelong double _Complexlong longshortsigned charunsignedunsigned charunsigned longunsigned long longunsigned short
Other types can built out of structures, unions, enumerations, arrays and pointers, and alternative names for existing
types can be defined with typedef.
The aggregate types are array types and structure types, i.e., those that have distinct identifiable components.
The derived types are array types, structure types, union types, pointer types and function types. All these types are defined in terms of other types, possibly recursively.
Types are identified in two ways. In a declaration, the name of an object, function or type alias is embedded in the type:
int arri[10]; int *arrpi[10]; int (*parri)[10];
arri, arrpi
and parri are the names of objects
being declared, and the type information surrounds them,
i.e., arri is an array of 10 ints;
arrpi is an array of 10 pointers to
ints;
parri is a pointer to an array of 10
ints. Of
course, it is often simpler than that, with trivially simple
embedding:
int x;
In some contexts, only the type can be identified, using the grammar of type-name:
- generic-association
type-name : assignment-expression- unary-expression
sizeof ( type-name )_Alignof ( type-name )- postfix-expression
-
( type-name ) { initializer-list }since C99; Structures -
( type-name ) { initializer-list , }since C99; Structures - cast-expression
( type-name ) cast-expression- alignment-specifier
_Alignas ( type-name )- atomic-type-specifier
_Atomic ( type-name )- type-name
specifier-qualifier-list abstract-declaratoropt- specifier-qualifier-list
type-specifier specifier-qualifier-listopttype-qualifier specifier-qualifier-listopt- type-specifier
voidcharshortintlongfloatdoublesignedunsigned-
_Boolsince C99 -
_Complexsince C99 -
_Imaginarysince C99 -
atomic-type-specifiersince C11 struct-or-union-specifierenum-specifiertypedef-name- struct-or-union-specifier
struct-or-union identifieropt { struct-declaration-list }struct-or-union identifier- typedef-name
identifier- struct-or-union
structunion- struct-declaration-list
struct-declarationstruct-declaration-list struct-declaration- struct-declaration
specifier-qualifier-list struct-declarator-listopt ;-
static_assert-declarationsince C11 - struct-declarator-list
struct-declaratorstruct-declarator-list struct-declarator- struct-declarator
declaratordeclaratoropt : constant-expression
The type-name
identifying arri is int[10],
arrpi is int
*[10], and parri is
int
(*)[10].