131 terms across 10 categories
Alignment is the address multiple an object must start on. An int typically wants a 4-byte address. A misaligned pointer is undefined behavior to dereference on some ABIs and merely slow on others.
alloca(n) allocates n bytes on the caller's stack and returns a pointer to them. The storage vanishes when the function returns. There is no free, and there is no portable failure return.
A buffer overflow is a write (or a read) past the end of an array or a malloc block. C does not check bounds. The extra bytes are other variables, saved registers, or heap metadata.
calloc(nmemb, size) allocates space for nmemb objects of size bytes each, zeros every byte, and returns the block — or NULL on failure. It is malloc plus memset plus an overflow check on the product.
A dangling pointer holds the address of an object whose lifetime has ended. The bits still look like an address. Using them is undefined behavior.
A double-free is calling free twice on the same allocation. The second call is undefined behavior. Allocators often crash, or they corrupt the heap so a later malloc blows up far from the bug.
free(p) returns a malloc/calloc/realloc block to the allocator. After the call, p is a dangling pointer. free(NULL) is a defined no-op.
malloc(n) asks the heap for n bytes and returns a pointer to them, or NULL if it cannot. The bytes are uninitialized. You free them exactly once with free.
memcpy copies n bytes between non-overlapping regions. memmove copies n bytes and is defined when the regions overlap. Same speed in the non-overlap case on a good libc; different contracts.
A memory leak is an allocation that is never freed and is no longer reachable. The process keeps the bytes until it exits. A long-running program grows without bound.
An off-by-one error uses an index or a length that is one too large or one too small. In C that is often a write to a[n] of an n-element array, or a string that lost its terminator.
Padding is unused bytes the compiler inserts so each struct member, and the struct as a whole, satisfies alignment. sizeof includes them. Your mental sizeof(a) + sizeof(b) often does not.
realloc(p, n) tries to resize a malloc block to n bytes. It returns a pointer to the (possibly moved) block, or NULL on failure. On failure, p is still valid.
sizeof is an operator that yields the size in bytes of a type or an expression. The result has type size_t. For most operands it is a compile-time constant.
The stack holds local variables that appear when a function is entered and vanish when it returns. The heap holds blocks you request explicitly, which stay alive until you free them, no matter which function does the freeing.
Use-after-free is reading or writing a block after free. The pointer is dangling. The bytes may now belong to a different allocation. The program is undefined.
Valgrind is a dynamic analysis tool, best known for Memcheck: it runs your program on a synthetic CPU and reports invalid reads and writes, use-after-free, double-free, and leaks.
A wild pointer is a pointer that has never been given a valid value. Its bits are leftover stack or heap garbage. Even reading the pointer, let alone dereferencing it, is undefined behavior.
An array is a contiguous sequence of objects of one type, addressed by an integer index starting at zero. In most expressions the array name decays to a pointer to the first element.
Turning C source into a running program happens in four stages: the preprocessor expands text, the compiler translates C into assembly, the assembler produces machine code, and the linker joins the pieces into one executable.
Conditional compilation uses preprocessor directives to keep or discard regions of source before the compiler sees them, so one codebase can produce different builds for different platforms or configurations.
Conditionals choose which statement runs based on a value. C offers if/else if/else for arbitrary tests and switch for dispatching on a single integer value.
const is a promise that you will not modify an object through this particular name or pointer. It constrains the access path, not necessarily the object, and in C it does not create a compile-time constant.
An enum names a set of integer constants and, in the same stroke, a type those constants belong to. The constants are int in portable C. The type is not a closed set: any int will convert to it.
errno is a thread-local integer that library functions set when they fail. Zero means "no error recorded." A non-zero value is a code from ` such as ENOENT or ENOMEM`.
An exit code is the integer a process reports to its parent when it terminates. Zero means success. Any other value means failure, with the exact meaning left to the program.
File I/O in hosted C goes through FILE streams: fopen to create one, fread / fwrite / fgets / fprintf to use it, and fclose to flush and release it.
A flexible array member is an incomplete array as the last member of a struct. You over-allocate the struct so the extra bytes become that array, keeping the header and the payload in one allocation.
A function pointer stores the address of a function, so the code that runs at a call site can be chosen at runtime. It is how C does callbacks, plugins, and dispatch tables.
A function is a named block of code you can call with arguments. C passes every argument by value. What looks like an "out" parameter is a pointer the callee writes through.
A header file holds the declarations that describe a module's interface, so other source files can use the module without seeing how it is implemented. #include copies the header's text into the file that includes it.
Implementation-defined behavior is behavior the C standard deliberately leaves to each compiler and platform, with the requirement that the choice is documented. The program stays well defined; the answer varies between targets.
An include guard is a pair of preprocessor directives that make a header's contents expand only the first time it is included, so including it twice in one translation unit is harmless.
Integer rank is C's ordering of integer types by width class. Promotions and the usual arithmetic conversions consult rank to decide the type of an expression when the operands differ.
Linkage is the rule that decides whether two declarations of the same name refer to the same object or function. C has external linkage, internal linkage, and no linkage.
Linking is the final build stage that matches every symbol a compiled object file references against a definition somewhere else, then patches the addresses so the pieces form one runnable program.
Loops repeat a block of statements. C provides for for counted iteration, while for "keep going while a condition holds", and do while for bodies that must run at least once.
A macro is a named piece of text that the preprocessor substitutes wherever the name appears. Object-like macros stand for a constant or snippet; function-like macros take arguments and paste them into the replacement text.
main is the function a hosted C program starts in. The runtime calls it after static initialization, and the integer it returns becomes the process exit status.
A multidimensional array in C is an array of arrays. int m2 is two rows of three ints, stored row-major in one contiguous block.
Operators combine operands into expressions. Precedence and associativity decide the grouping. Sequence points and the type of each operand decide whether the expression is defined at all.
Adding an integer to a pointer moves it by that many elements, not by that many bytes. The result is only valid while it stays inside the array the pointer came from, or one position past its end.
A pointer is a variable whose value is the address of another object. Its type records what kind of object lives at that address, which tells the compiler how many bytes to read and how to interpret them.
The preprocessor is a text-processing stage that runs before the C compiler. It copies in headers, expands macros, and removes conditional branches, producing the expanded source the compiler actually reads.
C's primitive types are the built-in integers, floating-point numbers, and void. Their sizes are minimums in the standard, not fixed widths, which is why portable code uses `` when it needs an exact number of bits.
Recursion is a function calling itself, directly or through a cycle of other functions. Each call gets a new stack frame. The chain has to stop, or the stack runs out.
restrict is a pointer qualifier that promises the object it points at will be accessed, for the lifetime of the pointer, only through that pointer and values derived from it. The compiler can then assume the object does not alias anything else.
A sequence point is a place in a program where every side effect from earlier evaluations has completed and no side effect from later evaluations has started. Modifying the same object twice with no sequence point between the two modifications is undefined behavior.
A signed integer can be negative. An unsigned integer cannot: arithmetic on it wraps modulo two to the power of its width. Mixing the two in one expression is one of C's most reliable sources of silent bugs.
size_t is the unsigned integer type of the result of sizeof. It is wide enough to count every byte in the largest object the implementation can create, and it is the type of array lengths, malloc arguments, and most library size parameters.
` is the C library for formatted I/O and FILE streams. printf, scanf, fopen, and the stdin / stdout / stderr` handles all live here.
A storage class specifier decides how an object or function is stored and how its name links. The specifiers are auto, register, static, extern, and _Thread_local.
` is the C library header for byte-string and raw-memory operations: copy, compare, search, and fill. Every function that takes a string assumes a '\0' terminator unless its name starts with mem`.
A C string is an array of char ending in a '\0' byte. The terminator is part of the value. There is no stored length, so every read walks until it finds that byte.
A struct is a named collection of members that sit together in memory. You access members with . on a struct value and -> on a pointer to one.
A translation unit is one source file after the preprocessor has finished with it, including every header it pulled in. The compiler translates one translation unit at a time and knows nothing about the others.
typedef gives an existing type a second name. It creates an alias, not a new type, so the compiler still treats the alias and the original as the same type everywhere.
Undefined behavior is any situation where the C standard imposes no requirements on what the program does. Because the compiler is allowed to assume it never happens, a single instance can change code far away from the mistake.
A union is a type whose members share one region of storage. The size is the size of the largest member, plus tail padding. Only one member holds a value at a time.
A variable is a named object with a type, a storage duration, and a scope. The type says how to interpret its bytes. The duration says how long those bytes exist. The scope says where the name is visible.
A variadic function accepts a fixed list of named parameters followed by an unknown number of extra arguments, written as .... The callee walks them with the macros in ``.
void * is a pointer to an object of unknown type. It can hold the address of any object and convert back to the original pointer type without loss, which is how C writes code that works on any type.
volatile tells the compiler that an object's value can change, or be observed, outside the abstract machine. Every read and write in the source must appear as a real memory access, in the order the thread wrote them relative to other volatiles.
An array is a block of objects. A pointer is the address of one object. In most expressions the array becomes a pointer to its first element, which is why the two feel interchangeable and then suddenly are not.
A binary tree is a node with at most two children, usually named left and right. The empty tree is a null pointer. Every child is itself a binary tree.
A binary search tree is a binary tree whose inorder walk is sorted. For every node, every value in the left subtree is less, and every value in the right subtree is greater (or not-less, if you allow duplicates on one side).
A circular buffer is a fixed array used as a queue by wrapping indices at the capacity. Head and tail chase each other around the ring. When they meet, the buffer is empty or full, and you need a rule to tell which.
A doubly linked list stores prev and next on every node. You can walk either direction and delete a node in O(1) if you already have a pointer to it.
A graph is a set of vertices and a set of edges between them. In C you usually store it as adjacency lists — an array of neighbor lists — or as an adjacency matrix of booleans or weights.
A hash table maps keys to values by hashing the key to a bucket index. Average lookup, insert, and delete are O(1). A bad hash or a full table turns that into O(n).
A binary heap is a complete binary tree stored in an array, where each parent is ordered with respect to its children. The minimum (or maximum) lives at index zero and can be removed in O(log n).
A singly linked list is a chain of nodes. Each node holds a value and a pointer to the next node. The list is the pointer to the first node, or NULL when empty.
An opaque pointer is a pointer to a struct the caller cannot see the members of. The header declares typedef struct HashTable HashTable; and functions that take HashTable *. The layout lives in one .c file.
A queue is a first-in, first-out collection. You enqueue at the back and dequeue at the front. The oldest item is the next one out.
A stack is a last-in, first-out collection. You push onto the top and pop from the top. The item that has been there the longest is the last one you see.
assert(e) from ` aborts the program if e is false. It is a debug check, not an error-handling path. Defining NDEBUG before the include turns every assert` into a no-op.
Check and cmocka are two common C unit-test frameworks. They give you test cases, fixtures, assertions that record failures without necessarily aborting, and a runner that can fork so a crash fails one case.
A fixture is the setup and teardown around a test: create the object, run the case, destroy the object even if the case failed. In C you write those two functions yourself or you register them with a framework.
Unit testing in C means compiling small programs that call your functions and check return values, outputs, and memory behavior. There is no built-in test runner. You add assert, a framework, or a pile of mains.
An atomic object is one the compiler and CPU will not tear or race on. C11 ` gives _Atomic` types and operations with an explicit memory order.
A condition variable lets a thread wait until another thread says a condition might be true. It is always used with a mutex that protects the condition's data.
A data race happens when two threads access the same memory, at least one access is a write, and the accesses are not both atomic and not separated by synchronization. In C the program then has undefined behavior.
Deadlock is a standstill where each thread waits for a resource another waiting thread holds. Nobody can make progress. The usual C form is two mutexes locked in opposite orders.
Memory order is the constraint you attach to an atomic operation that says how it may be reordered with other accesses. It is the C11 model for what "this write becomes visible before that read" means.
A mutex is a lock that only one thread can hold at a time. Code between lock and unlock is a critical section: other threads that want the same mutex wait.
POSIX threads (pthreads) are the standard C API for threads on Unix-like systems. pthread_create starts a function on a new thread. pthread_join waits for it to finish.
A race condition is a bug whose outcome depends on the unpredictable timing of threads, signals, or events. The program is logically wrong under some interleavings even when every single access is free of data races.
A semaphore is a counter that threads wait on and post to. wait decrements when the count is positive, or sleeps until it can. post increments and wakes a waiter.
Thread-local storage gives each thread its own instance of a variable. Writes in one thread do not race with writes in another, because they are different objects.
Breadth-first search visits a graph level by level. A queue holds the frontier. The first time you reach a vertex in an unweighted graph is a shortest path in number of edges.
Binary search finds a target in a sorted array by repeatedly discarding half of the remaining range. It runs in O(log n) comparisons and needs random access.
Bit manipulation uses C's bitwise operators to pack flags, test powers of two, and compute on integers as arrays of bits. The machine already works this way. The operators let you say so.
bsearch is the C library's binary search. It looks for a key in a sorted array using the same style of comparator as qsort, and returns a pointer to a matching element or NULL.
Depth-first search walks a graph by descending into one neighbor as far as it can before it backtracks. Recursion or an explicit stack holds the path.
Dynamic programming solves a problem by solving overlapping subproblems once, storing their answers, and combining them. The naive recursion is the specification. The table is the implementation.
A greedy algorithm builds a solution by taking the locally best choice at each step and never retracting it. It is fast when the problem has the greedy-choice property, and wrong when it does not.
A prefix-sum array stores the running total of a sequence. The sum of any slice a[l .. r] then becomes one subtraction: pref[r+1] - pref[l].
qsort is the C standard library's generic sort. It sorts an array in place using a comparison function you supply. The name hints at quicksort; the standard does not require that algorithm.
Algorithmic recursion solves a problem by solving smaller instances of the same problem and combining the answers. The call stack holds the unfinished work. A base case stops the descent.
A sliding window maintains a contiguous slice of an array that grows or shrinks as you scan. Each element enters and leaves the window at most once, so a class of subarray problems that look O(n^2) become O(n).
A sorting algorithm puts a sequence into order. Comparison sorts need at least O(n log n) comparisons in the worst case. In C you write one, or you call qsort.
Space complexity describes how the extra memory an algorithm uses grows with the input size. It is written in big-O, the same way as time, and it usually excludes the input itself.
Time complexity describes how the work an algorithm does grows as its input grows. It is written with big-O notation, which reports the growth rate of that work and deliberately ignores constant factors.
Two pointers is a technique that walks an array with a pair of indices that move toward a goal, often from both ends or as a slow runner and a fast runner. Many O(n^2) pair scans become O(n).
Binding writes a value into a prepared statement's parameter slot. sqlite3_bind_int, _int64, _double, _text, _blob, and _null are the usual calls. Indexes start at 1.
sqlite3_open and sqlite3_open_v2 create a connection to a SQLite database file or to an in-memory database. They return a sqlite3 * you must close. Failure still sometimes yields a handle you must close.
A prepared statement is SQL compiled once by sqlite3_prepare_v2 into a sqlite3_stmt *. You bind parameters, step rows, reset, and reuse. The SQL text is not concatenated with user data.
SQL injection is building a SQL string with untrusted text so the attacker can change the statement. In C the usual hole is sprintf(sql, "SELECT * FROM t WHERE name='%s'", user). The fix is a bound parameter.
SQLite is a C library that implements a SQL database in a single file (or in memory). You link -lsqlite3, include ``, and talk to it through a handle and a prepared-statement API. There is no server process.
sqlite3_step advances a prepared statement. SQLITE_ROW means a result row is ready to read. SQLITE_DONE means there are no more rows (or the write finished). Anything else is an error.
A SQLite transaction groups statements so they all commit or all roll back. BEGIN, your statements, then COMMIT or ROLLBACK. Without an explicit transaction, each statement is its own auto-commit transaction.
A callback is a function pointer the callee invokes when something happens. The caller supplies the function. The library decides when it runs.
Object-oriented C is a set of conventions: structs as data, functions as methods, opacity as encapsulation, embedding as inheritance, and vtables as virtual dispatch. The language does not enforce any of it.
The opaque-type pattern hides a struct's members behind an incomplete type in the public header. Callers hold a pointer and call functions. The layout can change without breaking their source.
A singleton is a type with one instance for the whole process. In C that is a file-scope static object plus a function that returns its address after initializing it once.
A state machine is an object whose next behavior depends on an explicit state. In C that is an enum plus a switch, or a function pointer that you replace as the state changes.
The strategy pattern in C is a struct of function pointers (or one function pointer) that you swap to change an algorithm without changing the caller. Sort, compress, and log are the usual examples.
CGI (Common Gateway Interface) is a convention for running a program per HTTP request. The web server sets environment variables, writes the body to stdin, and sends the program's stdout back as the response.
HTTP is a request/response protocol that usually rides on a TCP socket (or on TLS). In C you either write the text yourself or you let a library such as libcurl write it. There is no HTTP type in the language.
An HTTP server in C is a program that listens on a socket, accepts connections, reads a request, and writes a response. Production servers add TLS, multiplexing, and a routing table. The language still only gives you bytes.
libcurl is a C library for URL transfers. It speaks HTTP(S), FTP, and a long list of other protocols so your program does not have to write sockets and TLS by hand.
A socket is a file-descriptor-like endpoint for network I/O. In C you create one with socket, connect or bind it, then send / recv (or read / write) bytes. The C standard does not define this API; POSIX and Winsock do.
TLS (Transport Layer Security) encrypts a byte stream, usually a TCP socket, and authenticates the server with a certificate. HTTPS is HTTP over TLS. In C you use a library — commonly OpenSSL, LibreSSL, or mbedTLS — not a language feature.
Composition builds a larger object by storing other objects inside it, as members. In C that means a struct field that is another struct, or a pointer to one, rather than an inheritance relationship the language does not have.
A function-pointer method is a field in a struct that holds the address of a function. Calling obj->draw(obj) selects the implementation at run time, which is how C does per-object behavior without classes.
Inheritance by embedding puts a base struct as the first member of a derived struct. The derived object's address is then also the base object's address, so you can pass &derived->base — or a cast of derived — to APIs that expect the base type.
Init and cleanup are the constructor and destructor you write yourself. One function puts an object into a usable state. A matching function releases what it owns. C will not call them for you.
An interface struct is a fat pointer: a pointer to object state plus a pointer to a table of functions that object supports. Any type that can fill the table can be passed where the interface is expected.
An opaque type is a struct whose members are not visible in the header. Callers hold a pointer and call functions. Only the implementing .c file knows the layout.
C has no class keyword. An "object" is a struct plus the functions that take a pointer to it as their first argument. The type is the data. The functions are the methods.
A vtable is a struct of function pointers shared by every instance of one implementation. Each object holds a pointer to the table. A call through self->vptr->draw(self) is virtual dispatch, built by hand.