C Programming/Reference Tables
< C ProgrammingList of Keywords
ANSI C (C89)/ISO C (C90) keywords:
|
|
|
|
Very old compilers may not recognize some or all of the C89 keywords const, enum, signed, void, volatile, as well as any later standards' keywords.
Keywords added to ISO C99 (supported in most new compilers):
|
|
Keywords added to ISO C11 (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, including asm, cdecl, far, fortran, huge, interrupt, near, pascal, or typeof. However, they typically allow these keywords to be overridden by declarations when operating in standards-compliant modes (e.g., by defining a variable named typeof), 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 treats asm, __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., complex
or noreturn
). 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 including <stdbool.h>, the tokens bool
, true
, and false
can be used identically in either C99 or C++ without having to explicitly use _Bool in C99 or bool in C++.
See also the list of reserved identifiers.
C character sets
Programs written in C can read and write any character set.
The source program text for those programs, however, is usually limited to the following "basic C source character set":
- Lowercase and uppercase letters: a–z A–Z
- Decimal digits: 0–9
- Graphic characters: ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~
- Whitespace characters: space, horizontal tab, vertical tab, form feed, newline.
(In file containing the source program text, the end of a line of text is often not a single newline character, but C compilers treat the end of each line as if it were a single newline character).
Some coding standards mandate that only the above 96 characters are allowed in source code files.[1]
Practically all compilers allow the 3 remaining printable 7-bit ASCII characters '$', '@', and '`'; at least in string literals, but they are not entirely portable. Many compilers allow literal multibyte Unicode characters in string literals, but they are not entirely portable.
A few of the basic C source characters must be encoded to represent them in a string or character constant:
\\
\"
\'
\n
\t
\f
\v
Most compilers allow an even wider "basic C execution character set" to be represented in string literals and otherwise used in at run time: all the characters from the basic C source character set, along with
\r
\a
\b
\xhh , with each h replaced by a hexadecimal character, to portably represent arbitrary bytes (including \x00, the NULL byte)
\uhhhh or \Uhhhhhhhh encoding, with each h replaced by a hexadecimal character, to portably represent Unicode characters.
- ↑ "Joint strike fighter air vehicle C++ coding standards". section 4.4.2 Character Sets.
List of Standard Headers
ANSI C (C89)/ISO C (C90) headers:
Very old compilers may not include some or all of the following headers:
Headers added to ISO C (C94/C95) in Amendment 1 (AMD1):
Headers added to ISO C (C99) (Supported only in new compilers):
Headers added to ISO C (C11) (Supported only in new compilers):
|
|
|
Table of Operators
Operators in the same row of this table have the same precedence and the order of evaluation is decided by the associativity (left-to-right or right-to-left). Operators closer to the top of this table have higher 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 | |
+ -[1] | unary plus/minus operators | -num | |
++ -- | post-increment/decrement operators | num++ | |
++ -- | pre-increment/decrement operators | ++num | |
& | address-of operator | &data | |
* | indirection operator | *ptr | |
sizeof | sizeof operator for expressions | sizeof 123 | |
sizeof() | sizeof operator for 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 | ||
|| | see Logical Expressions | 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 represents foo = foo op bar) | num /= 10 | |
Comma Operator | Left to right | ||
, | i = 0, j = i + 1, k = 0 |
Table of Operators Footnotes
[1]Very old compilers may not recognize the unary + operator.
Table of Data Types
Type | Size in Bits | Comments | Alternative Names |
---|---|---|---|
Primitive Types in ANSI C (C89)/ISO C (C90) | |||
char | ≥ 8 |
|
— |
signed char | same as char |
|
— |
unsigned char | same as char |
|
— |
short | ≥ 16, ≥ size of char |
|
short int, signed short, signed short int |
unsigned short | same as short |
|
unsigned short int |
int | ≥ 16, ≥ size of short |
|
signed, signed int |
unsigned int | same as int |
|
unsigned |
long | ≥ 32, ≥ size of int |
|
long int, signed long, signed long int |
unsigned long | same as long |
|
unsigned long int |
float | ≥ size of char |
|
— |
double | ≥ size of float |
|
— |
long double | ≥ size of double |
|
— |
Primitive Types added to ISO C (C99) | |||
long long | ≥ 64, ≥ size of long |
|
long long int, signed long long, signed long long int |
unsigned long long | same as long long |
|
unsigned long long int |
intmax_t | the maximum width supported by the platform |
|
— |
uintmax_t | same as intmax_t |
|
— |
User Defined Types | |||
struct | ≥ sum of size of each member |
|
— |
union | ≥ size of the largest member |
|
— |
enum | ≥ size of char |
|
— |
typedef | same as the type being given a name |
|
— |
Derived Types[5] | |||
type* (pointer) | ≥ size of char |
|
— |
type [integer[6]] (array) | ≥ integer × size of type |
|
— |
type (comma-delimited list of types/declarations) (function) | — |
|
— |
Table of Data Types Footnotes
[1] -128 can be stored in two's-complement machines (i.e. most machines in existence). Very old compilers may not recognize the signed keyword. | ||
[2] -32768 can be stored in two's-complement machines (i.e. most machines in existence). Very old compilers may not recognize the signed keyword. | ||
[3] -2147483648 can be stored in two's-complement machines (i.e. most machines in existence). Very old compilers may not recognize the signed keyword. | ||
[4] -9223372036854775808 can be stored in two's-complement machines (i.e. most machines in existence). | ||
[5] The precedences in a declaration are: | ||
[], () (left associative) — Highest | ||
* (right associative) — Lowest | ||
[6] The standards do NOT place any restriction on the size/type of the integer, it's implementation dependent. The only mention in the standards is a reference that an implementation may have limits to the maximum size of memory block which can be allocated, and as such the limit on integer will be size_of_max_block/sizeof(type). |