Last modified on 6 September 2014, at 19:37

C Programming/Reference Tables

Previous: Code library Index Next: Compilers

List of KeywordsEdit

ANSI C (C89)/ISO C (C90) 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

Keywords added to ISO C (C99) (Supported only in new compilers):

  • _Bool
  • _Complex
  • _Imaginary
  • inline

Specific compilers may (in a non-standard-compliant mode) also treat some other words as keywords, including asm, cdecl, far, fortran, huge, interrupt, near, pascal, typeof.

Very old compilers may not recognize some or all of the C89 keywords const, enum, signed, void, volatile as well as the C99 keywords.

See also the list of reserved identifiers.

List of Standard HeadersEdit

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 OperatorsEdit

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 FootnotesEdit

[1]Very old compilers may not recognize the unary + operator.


Table of Data TypesEdit

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 chars. 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.
  • Signedness is implementation-defined.
  • Any encoding of 8 bits or less (e.g. ASCII) can be used to store characters.
  • Integer operations can be performed portably only for the range 0 ~ 127.
  • All bits contribute to the value of the char, i.e. there are no "holes" or "padding" bits.
signed char same as char
  • Characters stored like for type char.
  • Can store integers in the range -127 ~ 127 portably[1].
unsigned char same as char
  • Characters stored like for type char.
  • Can store integers in the range 0 ~ 255 portably.
short ≥ 16, ≥ size of char
  • Can store integers in the range -32767 ~ 32767 portably[2].
  • Used to reduce memory usage (although the resulting executable may be larger and probably slower as compared to using int.
short int, signed short, signed short int
unsigned short same as short
  • Can store integers in the range 0 ~ 65535 portably.
  • Used to reduce memory usage (although the resulting executable may be larger and probably slower as compared to using int.
unsigned short int
int ≥ 16, ≥ size of short
  • Represents the "normal" size of data the processor deals with (the word-size); this is the integral data-type used normally.
  • Can store integers in the range -32767 ~ 32767 portably[2].
signed, signed int
unsigned int same as int
  • Can store integers in the range 0 ~ 65535 portably.
unsigned
long ≥ 32, ≥ size of int
  • Can store integers in the range -2147483647 ~ 2147483647 portably[3].
long int, signed long, signed long int
unsigned long same as long
  • Can store integers in the range 0 ~ 4294967295 portably.
unsigned long int
float ≥ size of char
  • Used to reduce memory usage when the values used do not vary widely.
  • The floating-point format used is implementation defined and need not be the IEEE single-precision format.
  • unsigned cannot be specified.
double ≥ size of float
  • Represents the "normal" size of data the processor deals with; this is the floating-point data-type used normally.
  • The floating-point format used is implementation defined and need not be the IEEE double-precision format.
  • unsigned cannot be specified.
long double ≥ size of double
  • unsigned cannot be specified.

Primitive Types added to ISO C (C99)
long long ≥ 64, ≥ size of long
  • Can store integers in the range -9223372036854775807 ~ 9223372036854775807 portably[4].
long long int, signed long long, signed long long int
unsigned long long same as long long
  • Can store integers in the range 0 ~ 18446744073709551615 portably.
unsigned long long int
intmax_t the maximum width supported by the platform
uintmax_t same as intmax_t
  • Can store integers in the range 0 ~ (1 << n)-1, with 'n' the width of uintmax_t.

User Defined Types
struct ≥ sum of size of each member
  • Said to be an aggregate type.
union ≥ size of the largest member
  • Said to be an aggregate type.
enum ≥ size of char
  • Enumerations are a separate type from ints, 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.

Derived Types[5]
type*

(pointer)
≥ size of char
  • 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.
  • Pointers to different types may have different representations, which means they could also be of different sizes. So they are not convertible to one another.
  • Even in an implementation which guarantess all data pointers to be of the same size, function pointers and data pointers are in general incompatible with each other.
  • For functions taking variable number of arguments, the arguments passed must be of appropriate type, so even 0 must be cast to the appropriate type in such function-calls.
type [integer[6]]

(array)
integer × size of type
  • The brackets ([]) follow the identifier name in a declaration.
  • In a declaration which also initializes the array (including a function parameter declaration), the size of the array (the integer) can be omitted.
  • 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)
  • Functions declared without any storage class are extern.
  • The parentheses (()) follow the identifier name in a declaration, e.g. a 2-arg function pointer: int (* fptr) (int arg1, int arg2).

Table of Data Types FootnotesEdit

[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).

Previous: Code library Index Next: Compilers