C Reference Manual
This is a quick reference manual — no need to read it cover to cover. Just look things up when you need them.
Keyword Quick Reference
C89 Keywords (32)
| Keyword |
Description |
auto |
Automatic storage duration (default) |
break |
Exit loop or switch |
case |
switch branch label |
char |
Character type |
const |
Constant qualifier |
continue |
Jump to next loop iteration |
default |
switch default branch |
do |
do-while loop |
double |
Double-precision floating point |
else |
if-else else branch |
enum |
Enumeration type |
extern |
External linkage declaration |
float |
Single-precision floating point |
for |
for loop |
goto |
Unconditional jump |
if |
Conditional statement |
int |
Integer type |
long |
Long integer qualifier |
register |
Register storage hint |
return |
Function return |
short |
Short integer qualifier |
signed |
Signed qualifier |
sizeof |
Get type or variable size |
static |
Static storage duration or internal linkage |
struct |
Structure |
switch |
Multi-branch selection |
typedef |
Type alias |
union |
Union |
unsigned |
Unsigned qualifier |
void |
Empty type |
volatile |
Prevent optimization qualifier |
while |
while loop |
C99 New Keywords (5)
| Keyword |
Description |
_Bool |
Boolean type (usually via bool macro) |
_Complex |
Complex number type |
_Imaginary |
Imaginary number type |
inline |
Inline function hint |
restrict |
Pointer aliasing restriction |
C11 New Keywords (7)
| Keyword |
Description |
_Alignas |
Alignment specifier |
_Alignof |
Get alignment requirement |
_Atomic |
Atomic type |
_Generic |
Generic selection |
_Noreturn |
Function does not return |
_Static_assert |
Static assertion |
_Thread_local |
Thread-local storage |
| Specifier |
Output Type |
Example |
%d / %i |
Signed decimal integer |
printf("%d", 42) → 42 |
%u |
Unsigned decimal integer |
printf("%u", 42U) → 42 |
%o |
Unsigned octal |
printf("%o", 8) → 10 |
%x |
Unsigned hexadecimal (lowercase) |
printf("%x", 255) → ff |
%X |
Unsigned hexadecimal (uppercase) |
printf("%X", 255) → FF |
%f |
Decimal floating point |
printf("%f", 3.14) → 3.140000 |
%e |
Scientific notation (lowercase e) |
printf("%e", 0.001) → 1.000000e-03 |
%E |
Scientific notation (uppercase E) |
printf("%E", 0.001) → 1.000000E-03 |
%g |
Auto-select %f or %e |
printf("%g", 0.0001) → 0.0001 |
%c |
Character |
printf("%c", 'A') → A |
%s |
String |
printf("%s", "hi") → hi |
%p |
Pointer address |
printf("%p", ptr) → 0x7ffd... |
%ld |
long |
printf("%ld", 100000L) |
%lld |
long long |
printf("%lld", 1LL<<40) |
%zu |
size_t |
printf("%zu", sizeof(int)) |
%% |
Percent sign itself |
printf("100%%") → 100% |
printf Modifiers
| Modifier |
Meaning |
Example |
%- |
Left-align |
"%-10s" |
%0 |
Pad with zeros |
"%05d" → 00042 |
%m |
Minimum field width |
"%10d" |
%.n |
Precision |
"%.2f" → 3.14 |
| Specifier |
Read Type |
%d |
int |
%u |
unsigned int |
%ld |
long |
%f |
float |
%lf |
double |
%c |
Character |
%s |
String (stops at whitespace) |
%[...] |
Scanset |
%*d |
Read but discard |
Escape Character Table
| Escape Sequence |
Meaning |
ASCII Value |
\a |
Alert (bell) |
7 |
\b |
Backspace |
8 |
\f |
Form feed |
12 |
\n |
Newline |
10 |
\r |
Carriage return |
13 |
\t |
Horizontal tab |
9 |
\v |
Vertical tab |
11 |
\\ |
Backslash |
92 |
\' |
Single quote |
39 |
\" |
Double quote |
34 |
\0 |
Null character |
0 |
\ooo |
Octal value |
— |
\xhh |
Hexadecimal value |
— |
Operator Precedence Table
Listed from highest to lowest. Operators on the same line have equal precedence:
| Precedence |
Operators |
Associativity |
Description |
| 1 |
() [] -> . ++(postfix) --(postfix) |
Left→Right |
Postfix |
| 2 |
++(prefix) --(prefix) + - ! ~ *(deref) &(address) sizeof (type) |
Right→Left |
Unary |
| 3 |
* / % |
Left→Right |
Multiplicative |
| 4 |
+ - |
Left→Right |
Additive |
| 5 |
<< >> |
Left→Right |
Shift |
| 6 |
< <= > >= |
Left→Right |
Relational |
| 7 |
== != |
Left→Right |
Equality |
| 8 |
& |
Left→Right |
Bitwise AND |
| 9 |
^ |
Left→Right |
Bitwise XOR |
| 10 |
| |
Left→Right |
Bitwise OR |
| 11 |
&& |
Left→Right |
Logical AND |
| 12 |
|| |
Left→Right |
Logical OR |
| 13 |
?: |
Right→Left |
Conditional |
| 14 |
= += -= *= /= %= &= ^= |= <<= >>= |
Right→Left |
Assignment |
| 15 |
, |
Left→Right |
Comma |
💡 Tip: Mnemonic: Unary → Multiplicative → Additive → Shift → Relational → Equality → Bitwise AND → XOR → Bitwise OR → Logical AND → Logical OR → Conditional → Assignment → Comma
stdio.h
| Function |
Purpose |
printf |
Formatted output to stdout |
fprintf |
Formatted output to file |
sprintf |
Formatted output to string |
snprintf |
Formatted output to string (safe) |
scanf |
Formatted read from stdin |
fscanf |
Formatted read from file |
sscanf |
Formatted read from string |
fopen |
Open file |
fclose |
Close file |
fgetc |
Read one character |
fputc |
Write one character |
fgets |
Read one line |
fputs |
Write string |
fread |
Binary read |
fwrite |
Binary write |
fseek |
Set file position |
ftell |
Get file position |
rewind |
Reset file position to beginning |
feof |
Check end of file |
ferror |
Check file error |
fflush |
Flush buffer |
remove |
Delete file |
rename |
Rename file |
tmpfile |
Create temporary file |
perror |
Print error message |
stdlib.h
| Function |
Purpose |
malloc |
Dynamic memory allocation |
calloc |
Allocate and zero memory |
realloc |
Reallocate memory |
free |
Release memory |
atoi |
String to int |
atol |
String to long |
atof |
String to double |
strtol |
String to long (safe) |
strtod |
String to double (safe) |
rand |
Generate random number |
srand |
Set random seed |
qsort |
Quick sort |
bsearch |
Binary search |
abs |
Integer absolute value |
labs |
long absolute value |
exit |
Terminate program |
atexit |
Register exit function |
system |
Execute system command |
getenv |
Get environment variable |
string.h
| Function |
Purpose |
strcpy |
String copy |
strncpy |
String copy (safe) |
strcat |
String concatenation |
strncat |
String concatenation (safe) |
strcmp |
String comparison |
strncmp |
String comparison (with length) |
strlen |
String length |
strchr |
Find character (from left) |
strrchr |
Find character (from right) |
strstr |
Find substring |
strtok |
String tokenization |
memcpy |
Memory copy |
memmove |
Memory move (allows overlap) |
memset |
Memory fill |
memcmp |
Memory comparison |
math.h
| Function |
Purpose |
fabs |
Floating-point absolute value |
sqrt |
Square root |
pow |
Power |
ceil |
Round up |
floor |
Round down |
round |
Round to nearest |
fmod |
Floating-point remainder |
log |
Natural logarithm |
log10 |
Common logarithm |
sin |
Sine |
cos |
Cosine |
tan |
Tangent |
asin |
Arc sine |
acos |
Arc cosine |
atan |
Arc tangent |
atan2 |
Arc tangent (two arguments) |
ctype.h
| Function |
Purpose |
isalpha |
Is letter |
isdigit |
Is digit |
isalnum |
Is letter or digit |
isupper |
Is uppercase |
islower |
Is lowercase |
isspace |
Is whitespace |
ispunct |
Is punctuation |
isprint |
Is printable |
toupper |
Convert to uppercase |
tolower |
Convert to lowercase |
time.h
| Function/Macro |
Purpose |
time |
Get current time |
clock |
Get CPU clock ticks |
localtime |
Convert to local time |
gmtime |
Convert to UTC time |
strftime |
Format time |
difftime |
Calculate time difference |
mktime |
Convert tm to time_t |
CLOCKS_PER_SEC |
Clock ticks per second |
assert.h
| Function/Macro |
Purpose |
assert(expr) |
Assert; terminate on failure |
NDEBUG |
Disable assert when defined |
errno.h
| Symbol |
Purpose |
errno |
Global error code variable |
EDOM |
Domain error |
ERANGE |
Range error |
Data Type Range Quick Reference
| Type |
Size (bytes) |
Minimum |
Maximum |
char |
1 |
-128 |
127 or 0/255 |
signed char |
1 |
-128 |
127 |
unsigned char |
1 |
0 |
255 |
short |
2 |
-32768 |
32767 |
unsigned short |
2 |
0 |
65535 |
int |
4 |
-2147483648 |
2147483647 |
unsigned int |
4 |
0 |
4294967295 |
long |
4/8 |
Platform-dependent |
Platform-dependent |
unsigned long |
4/8 |
0 |
Platform-dependent |
long long |
8 |
-9223372036854775808 |
9223372036854775807 |
float |
4 |
~1.2e-38 |
~3.4e+38 |
double |
8 |
~2.2e-308 |
~1.8e+308 |