Previous: Code library | C Programming | Next: Compilers |
Very old compilers may not recognize some or all of the C89 keywordsconst
,enum
,signed
,void
,volatile
, as well as any later standards' keywords.
|
|
|
|
These are supported in most new compilers.
|
|
These are supported only in some newer compilers
|
|
|
Although not technically a keyword, C99-capable preprocessors/compilers additionally recognize the special preprocessor operator_Pragma
, which acts as an alternate form of the#pragma
directive that can be used from within macro expansions. For example, the following code will cause some compilers (incl. GCC, Clang) to emit a diagnostic message:
#define EMIT_MESSAGE(str) EMIT_PRAGMA(message(str))#define EMIT_PRAGMA(content) _Pragma(#content)EMIT_MESSAGE("Hello, world!")
Some compilers use a slight variant syntax; in particular, MSVC supports__pragma
instead of_Pragma
.
Specific compilers may also—in a non-standards-compliant mode, or with additional syntactic markers like__extension__
—treat some other words as keywords, includingasm
,cdecl
,far
,fortran
,huge
,interrupt
,near
,pascal
, ortypeof
. However, they typically allow these keywords to be overridden by declarations when operating in standards-compliant modes (e.g., by defining a variable namedtypeof
), in order to avoid introducing incompatibilities with existing programs. In order to ensure the compiler can maintain access to extension features, these compilers usually have an additional set of proper keywords beginning with two underscores (__
). For example, GCC treatsasm
,__asm
, and__asm__
somewhat identically, but the latter two are always guaranteed to have the expected meaning since they can't be overridden.
Many of the newly introduced keywords—namely, those beginning with an underscore and capital letter like_Noreturn
or_Imaginary
—are intended to be used only indirectly in most situations. Instead, the programmer should prefer the use of standard headers such as<stdbool.h>
or<stdalign.h>
, which typically use the preprocessor to establish an all-lower-case variant of the keyword (e.g.,
orcomplex
). These headers serve the purpose of enabling C and C++ code, as well as code targeting different compilers or language versions, to interoperate more cleanly. For example, by includingnoreturn
<stdbool.h>
, the tokens
,bool
, andtrue
can be used identically in either C99 or C++ without having to explicitly usefalse
_Bool
in C99 orbool
in C++.
See also the list of reserved identifiers[1].
Operators in the same row of this table have the sameprecedence and the order of evaluation is decided by theassociativity (left-to-right orright-to-left). Operators closer to the top of this table havehigher precedence than those in a subsequent group.
Operators | Description | Example Usage | Associativity |
---|---|---|---|
Postfix operators | Left to right | ||
() | function call operator | swap (x, y) | |
[] | array index operator | arr [i] | |
. | member access operator for an object of struct/union type or a reference to it | obj.member | |
-> | member access operator for a pointer to an object of struct/union type | ptr->member | |
Unary Operators | Right to left | ||
! | logical not operator | !eof_reached | |
~ | bitwise not operator | ~mask | |
+ - [2] | unary plus/minus operators | -num | |
++ -- | post-increment/decrement operators | num++ | |
++ -- | pre-increment/decrement operators | ++num | |
& | address-of operator | &data | |
* | indirection operator | *ptr | |
sizeof | sizeof operatorfor expressions | sizeof 123 | |
sizeof() | sizeof operatorfor types | sizeof (int) | |
(type) | cast operator | (float)i | |
Multiplicative Operators | Left to right | ||
* / % | multiplication, division and modulus operators | celsius_diff * 9.0 / 5.0 | |
Additive Operators | Left to right | ||
+ - | addition and subtraction operators | end - start + 1 | |
Bitwise Shift Operators | Left to right | ||
<< | left shift operator | bits << shift_len | |
>> | right shift operator | bits >> shift_len | |
Relational Inequality Operators | Left to right | ||
< > <= >= | less-than, greater-than, less-than or equal-to, greater-than or equal-to operators | i < num_elements | |
Relational Equality Operators | Left to right | ||
== != | equal-to, not-equal-to | choice != 'n' | |
Bitwise And Operator | Left to right | ||
& | bits & clear_mask_complement | ||
Bitwise Xor Operator | Left to right | ||
^ | bits ^ invert_mask | ||
Bitwise Or Operator | Left to right | ||
| | bits | set_mask | ||
Logical And Operator | Left to right | ||
&& | arr != 0 && arr->len != 0 | ||
Logical Or Operator | Left to right | ||
|| | arr == 0 || arr->len == 0 | ||
Conditional Operator | Right to left | ||
?: | size != 0 ? size : 0 | ||
Assignment Operators | Right to left | ||
= | assignment operator | i = 0 | |
+= -= *= /= | shorthand assignment operators ( foo op=bar representsfoo =foo opbar ) | num /= 10 | |
Comma Operator | Left to right | ||
, | i = 0, j = i + 1, k = 0 |
Type | Size in Bits | Comments | Alternative Names |
---|---|---|---|
Primitive Types in ANSI C (C89)/ISO C (C90) | |||
char | ≥ 8 |
| — |
signedchar | same aschar |
| — |
unsignedchar | same aschar |
| — |
short | ≥ 16, ≥ size ofchar |
| shortint ,signedshort ,signedshortint |
unsignedshort | same asshort |
| unsignedshortint |
int | ≥ 16, ≥ size ofshort |
| signed ,signedint |
unsignedint | same asint |
| unsigned |
long | ≥ 32, ≥ size ofint |
| longint ,signedlong ,signedlongint |
unsignedlong | same aslong |
| unsignedlongint |
float | ≥ size ofchar |
| — |
double | ≥ size offloat |
| — |
longdouble | ≥ size ofdouble |
| — |
Primitive Types added to ISO C (C99) | |||
longlong | ≥ 64, ≥ size oflong |
| longlongint ,signedlonglong ,signedlonglongint |
unsignedlonglong | same aslonglong |
| unsignedlonglongint |
intmax_t | the maximum width supported by the platform |
| — |
uintmax_t | same asintmax_t |
| — |
User Defined Types | |||
struct | ≥ sum of size of each member |
| — |
union | ≥ size of the largest member |
| — |
enum | ≥ size ofchar |
| — |
typedef | same as the type being given a name |
| — |
Derived Types[7] | |||
type* (pointer) | ≥ size ofchar |
| — |
type [integer[8]] (array) | ≥integer × size oftype |
| — |
type (comma-delimited list of types/declarations) (function) | — |
| — |
Programs written in C can read and write any character set, provided the libraries that support them are included/used.
The source code for C programs, however, is usually limited to the ASCII character set.
In a file containing source code, the end of a line is sometimes, depending on the operating system it was created on not a newline character but compilers treat the end of each line as if it were a single newline character.
Virtually all compilers allow the$,@, and` characters in string constants. Many compilers also allow literal multibyte Unicode characters, but they are not portable.
Certain characters must be escaped with a backslash to represent themselves in a string or character constant. These are:
|
|
|
Additionally, some compilers allow these characters:
\r
Carriage return\a
Alert (audible bell)\b
Backspace\xhh, where the 'h' characters are hexadecimal digits, is used to represent arbitrary bytes (including\x00, the zero byte).
\uhhhh or\Uhhhhhhhh, where the 'h' characters are hexadecimal digits, is used to portably represent Unicode characters.
+
operator.signed
keywordsigned
keywordsigned
keyword[] ,() (left associative) — Highest |
* (right associative) — Lowest |
Previous: Code library | C Programming | Next: Compilers |