C Reference
Every C keyword, operator, preprocessor directive and standard library function in one place. Concise, accurate pages with live examples that compile and run on GCC 15 in C23 mode, with syntax, parameters and return values.
Keywords and Statements
-
if and elseConditional execution. -
switchMulti-way branching and fall-through. -
forCounter-based loops. -
while and do-whileCondition-controlled loops. -
break and continueLeaving and skipping iterations. -
gotoJumps and legitimate uses. -
returnReturning from functions. -
staticInternal linkage and persistent locals. -
externExternal linkage and declarations. -
constRead-only objects. -
volatilePreventing optimization of accesses. -
restrictNon-aliasing pointers. -
register and autoStorage class specifiers and type inference. -
inlineInline functions. -
typedefType aliases. -
structStructures. -
unionUnions. -
enumEnumerations. -
sizeofSize of types and objects. -
alignof and alignasAlignment. -
typeofType of an expression (C23). -
bool, true and falseBoolean type (C23 keywords). -
nullptrThe null pointer constant (C23). -
constexprCompile-time constants (C23). -
static_assertCompile-time assertions. -
_GenericGeneric selection. -
thread_localThread-local storage. -
noreturnFunctions that do not return. -
Attributes[[nodiscard]], [[maybe_unused]] and friends (C23). -
_ComplexComplex numbers. -
_BitIntBit-precise integers (C23). -
Reserved wordsThe keyword list.
Types and Literals
-
charCharacter types and signedness. -
int, short and longInteger types. -
long long64-bit integers. -
unsigned typesUnsigned arithmetic and wraparound. -
float and doubleFloating-point types. -
long doubleExtended precision. -
Fixed-width integersint32_t and friends. -
size_t and ptrdiff_tSizes and differences. -
intptr_t and uintptr_tPointer-sized integers. -
voidThe empty type. -
_Bool and boolBooleans. -
ArraysDeclaring and using arrays. -
Variable length arraysVLAs and their risks. -
PointersDeclaring and dereferencing. -
Pointer arithmeticAdding and subtracting pointers. -
Function pointersDeclaring and calling. -
Strings in CNull-terminated character arrays. -
LiteralsInteger, floating, character and string literals. -
Compound literals(type){...}. -
Designated initializers.field = and [index] =. -
Flexible array membersTrailing arrays in structs. -
Bit-fieldsPacked fields. -
Struct padding and alignmentLayout. -
Type conversionsInteger promotions and usual arithmetic conversions. -
CastsExplicit conversions. -
Type qualifiersconst, volatile, restrict, _Atomic. -
Integer and float limitslimits.h and float.h constants. -
EndiannessByte order. -
Undefined behaviorCommon causes. -
Implementation-defined behaviorWhat varies.
Operators and Expressions
-
Arithmetic operators+, -, *, /, %. -
Increment and decrement++ and --. -
Assignment operators= and compound assignment. -
Relational and equality operators<, ==, != and friends. -
Logical operators&&, ||, !. -
Bitwise operators&, |, ^, ~. -
Shift operators<< and >>. -
Conditional operator?:. -
Comma operatorSequencing expressions. -
Address-of and dereference& and *. -
Member access. and ->. -
Subscript operatora[i] and pointer equivalence. -
sizeof operatorEvaluation rules. -
Operator precedenceThe table. -
Sequence points and evaluation orderUnspecified order. -
Short-circuit evaluation&& and || rules. -
Integer overflowSigned vs. unsigned. -
Lvalues and rvaluesWhat can be assigned. -
Integer division and moduloRounding rules. -
Comparing floating-point numbersEpsilons and pitfalls.
Functions and Scope
-
Function declarationsPrototypes and definitions. -
Parameters and argumentsPass by value. -
Pointer parametersSimulating pass by reference. -
Array parametersDecay to pointers. -
Return valuesReturning structs and pointers. -
RecursionRecursive functions. -
Variadic functionsstdarg.h. -
main()Program entry and arguments. -
Static local variablesPersistent state. -
Scope and lifetimeBlock, file and function scope. -
LinkageInternal and external linkage. -
Storage durationAutomatic, static, thread, allocated. -
CallbacksFunction pointer callbacks. -
Inline functionsinline semantics. -
Header filesInclude guards and design. -
Opaque typesHiding implementation. -
const correctnessUsing const. -
Macros vs. functionsWhen to use which.
Preprocessor
-
#includeIncluding headers. -
#defineObject-like and function-like macros. -
#undefRemoving macros. -
#if, #ifdef, #ifndefConditional compilation. -
#elif, #else, #endifChained conditions. -
#error and #warningDiagnostics. -
#pragma and _PragmaCompiler directives. -
#lineLine control. -
#embedEmbedding binary data (C23). -
The # operatorStringification. -
The ## operatorToken pasting. -
Variadic macros__VA_ARGS__ and __VA_OPT__. -
Predefined macros__FILE__, __LINE__, __STDC_VERSION__. -
Include guards#ifndef and #pragma once. -
Macro pitfallsParenthesization and double evaluation. -
X macrosTable-driven code. -
__has_include and feature testsDetecting features. -
assert macroassert.h.
stdio.h
-
printfFormatted output. -
fprintf and dprintfOutput to streams. -
sprintf and snprintfFormatting into buffers. -
printf format specifiersThe specifier table. -
scanfFormatted input. -
sscanf and fscanfParsing input. -
scanf pitfallsWhy scanf is tricky. -
puts and fputsWriting strings. -
putchar and putcWriting characters. -
getchar and getcReading characters. -
fgetsSafe line reading. -
fopenOpening files. -
fcloseClosing files. -
fread and fwriteBinary I/O. -
fseek, ftell and rewindFile position. -
feof and ferrorError and end-of-file. -
fflushFlushing output. -
setvbuf and bufferingStream buffering. -
remove and renameFile operations. -
tmpfileTemporary files. -
perrorError messages. -
stdin, stdout and stderrStandard streams. -
ungetcPushing back characters. -
getlinePOSIX line reading. -
FILEThe stream type. -
fgetc and fputcCharacter I/O. -
EOF and BUFSIZI/O constants. -
freopenRedirecting streams. -
fmemopen and open_memstreamIn-memory streams.
stdlib.h
-
mallocAllocating memory. -
callocAllocating zeroed memory. -
reallocResizing allocations. -
freeReleasing memory. -
aligned_allocAligned allocation. -
Memory errorsLeaks, double free, use after free. -
atoi, atol and atofSimple conversion. -
strtol and strtoulRobust integer parsing. -
strtod and strtofParsing floats. -
abs, labs and divInteger helpers. -
rand and srandPseudo-random numbers. -
qsortSorting arrays. -
bsearchBinary search. -
exit and atexitTerminating normally. -
abort and _ExitAbnormal termination. -
getenvEnvironment variables. -
systemRunning commands. -
EXIT_SUCCESS and EXIT_FAILUREExit status. -
Multibyte conversionmbstowcs and friends. -
Memory ownership patternsWho frees what.
string.h
-
strlenString length. -
strcpy and strncpyCopying strings. -
strcat and strncatConcatenation. -
strcmp and strncmpComparison. -
strchr and strrchrFinding characters. -
strstrFinding substrings. -
strtokTokenizing. -
strspn and strcspnSpan functions. -
strpbrkFinding any of a set. -
strdup and strndupDuplicating strings. -
strerrorError text. -
memcpyCopying memory. -
memmoveOverlapping copies. -
memsetFilling memory. -
memcmpComparing memory. -
memchrSearching memory. -
Safe string handlingBounds-checked patterns and pitfalls. -
strcoll and strxfrmLocale-aware comparison.
ctype.h, math.h and others
-
isalpha, isdigit, isalnumCharacter classes. -
isspace, isupper, islowerMore classes. -
toupper and tolowerCase conversion. -
ispunct, isprint, iscntrlOther classes. -
sqrt and powRoots and powers. -
fabs, fmod, remainderAbsolute value and remainder. -
floor, ceil, round, truncRounding. -
lround and nearbyintRounding to integers. -
sin, cos, tan, atan2Trigonometry. -
exp, log, log10, log2Exponentials. -
hypot, cbrt, fmaSpecial functions. -
isnan, isinf, isfinite, fpclassifyClassification. -
Math constantsINFINITY, NAN, M_PI. -
fenv.hFloating-point environment. -
complex.hComplex arithmetic. -
tgmath.hType-generic math. -
stdbit.hBit utilities (C23). -
stdckdint.hChecked integer arithmetic (C23). -
time and clockTime functions. -
localtime and gmtimeBroken-down time. -
strftimeFormatting time. -
mktime and difftimeTime arithmetic. -
timespec_get and clock_gettimeHigh-resolution time. -
errnoError codes. -
signal.hSignals. -
setjmp and longjmpNon-local jumps. -
assert.hAssertions. -
stdarg.hVariable arguments. -
stddef.hoffsetof, ptrdiff_t, NULL. -
stdint.hInteger types. -
inttypes.hFormat macros. -
limits.hInteger limits. -
float.hFloat limits. -
locale.hLocales. -
wchar.hWide characters. -
uchar.hUnicode characters. -
stdalign.h and stdnoreturn.hLegacy macros. -
threads.hC11 threads. -
stdatomic.hAtomics. -
iso646.hAlternative spellings.
POSIX and Systems
-
unistd.hPOSIX basics. -
forkCreating processes. -
exec familyRunning programs. -
wait and waitpidChild processes. -
pipePipes. -
open, read, write, closeFile descriptors. -
statFile information. -
opendir and readdirDirectories. -
pthread_createPOSIX threads. -
pthread_mutexMutexes. -
pthread_condCondition variables. -
Socketssocket, bind, listen, accept. -
select and pollI/O multiplexing. -
mmapMemory mapping. -
sigactionRobust signals. -
getoptCommand-line parsing. -
dlopenDynamic loading.
Concepts and Tools
-
Program memory layoutStack, heap, data, text. -
Stack vs. heapWhere objects live. -
Undefined behavior catalogExamples and defenses. -
Strict aliasingAliasing rules. -
Buffer overflowsCauses and prevention. -
Secure codingCERT-style guidance. -
SanitizersASan, UBSan, TSan (read-only). -
ValgrindMemory checking (read-only). -
Debugging with gdbDebugger (read-only). -
Compilersgcc, clang, MSVC. -
Compiler flagsWarnings and optimization. -
Compiling and linkingObject files and libraries. -
Make and build systemsMakefiles (read-only). -
C standardsC89 to C23. -
What is new in C23Feature tour. -
What is new in C11Feature tour. -
C coding styleConventions. -
Common C idiomsPatterns. -
Data structures in CLists, stacks, hash tables. -
PortabilityWriting portable C. -
GlossaryKey C terms.
Nothing matches โโ. Try the site search.