From Wikibooks, open books for an open world
ANSI (American National Standards Institute) C (C89)/ISO C (C90)[edit | edit source]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.
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
These are supported in most new compilers.
_Bool
_Complex
_Imaginary
inline
These are supported only in some newer compilers
alignof
_Alignas
_Atomic
_Generic
_Noreturn
_Static_assert
_Thread_local
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.,
or complex
). 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 noreturn
<stdbool.h>
, the tokens
, bool
, and true
can be used identically in either C99 or C++ without having to explicitly use false
_Bool
in C99 or bool
in C++.
See also the list of reserved identifiers [1].
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
obj.member
->
member access operator
ptr->member
!
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 operator for expressions sizeof 123
sizeof()
sizeof operator for types sizeof (int)
(type)
cast operator (float)i
* / %
multiplication, division and
celsius_diff * 9.0 / 5.0
+ -
addition and subtraction operators end - start + 1
<<
left shift operator bits << shift_len
>>
right shift operator bits >> shift_len
< > <= >=
less-than, greater-than, less-than or
i < num_elements
== !=
equal-to, not-equal-to choice != 'n'
&
bits & clear_mask_complement
^
bits ^ invert_mask
|
bits | set_mask
&&
arr != 0 && arr->len != 0
||
arr == 0 || arr->len == 0
Conditional Operator Right to left ?:
size != 0 ? size : 0
=
assignment operator i = 0
+= -= *= /=
%= &= |= ^=
<<= >>=
shorthand assignment operators
foo op= bar
representsfoo = foo op bar
) num /= 10
,
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
sizeof
gives the size in units of char
s. These "C bytes" need not be 8-bit bytes (though commonly they are); the number of bits is given by the CHAR_BIT
macro in the limits.h
header.signed char
same as char
char
.unsigned char
same as char
char
.short
≥ 16, ≥ size of char
int
.short int
, signed short
, signed short int
unsigned short
same as short
int
.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
unsigned
cannot be specified.double
≥ size of float
unsigned
cannot be specified.long double
≥ size of double
unsigned
cannot be specified.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
struct
≥ sum of size of each member
union
≥ size of the largest member
enum
≥ size of char
int
s, though they are mutually convertible.typedef
same as the type being given a name
typedef
has syntax similar to a storage class like static
, register
or extern
.type*
(pointer)
≥ size ofchar
0
always represents the null pointer (an address where no data can be placed), irrespective of what bit sequence represents the value of a null pointer.0
must be cast to the appropriate type in such function-calls.type [integer[8]]
(array)
≥ integer × size oftype
[]
) follow the identifier name in a declaration.type []
is not the same as type*
. Only under some circumstances one can be converted to the other.type (comma-delimited list of types/declarations)
(function)
—extern
.()
) follow the identifier name in a declaration, e.g. a 2-arg function pointer: int (* fptr) (int arg1, int arg2)
.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:
\\
Literal backslash\"
Literal double quote\'
Literal single quote\n
Newline\t
Horizontal tab\f
Form feed\v
Vertical tabAdditionally, 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 RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4