Skip to content

C Basics

Glossary

144 terms from C Basics, in plain words, each with the chapter that teaches it.

#

#define
A preprocessor line that names a value. Wherever SHOP_NAME appears later, the preprocessor puts in its text first.
#include
A preprocessor line that pastes a header file's text into your file. Angle brackets mean a compiler header and double quotes mean your own.

A

Address
The number of a byte in memory. A variable such as qty lives at an address.
Address-of operator (&)
The `&` operator gives the address of a variable. `&qty` means where qty lives, which is why scanf needs `&qty`.
AddressSanitizer (ASan)
A sanitizer switched on with `-fsanitize=address`. It stops a program at the first bad memory access, such as writing past a heap block, and reports the kind of bug and the line.
argc and argv
The two parameters of `int main(int argc, char *argv[])`. argc counts the words typed on the command line, and argv holds them as strings, with the program's name in argv[0].
Argument
A value you pass to a function when you call it. In line_total(475, 2), the values 475 and 2 are the arguments.
Array
A row of values of one type, side by side in memory. Each value is reached by its index, counting from 0, like the prices of Kettle & Crane's drinks.
Arrow (->)
The `->` operator reaches a struct member through a pointer. `p->cents` means `(*p).cents`.
Assignment
Storing a new value in a variable with `=`. In C, `=` means store, not equals.

B

Backtrace
The chain of function calls that led to the current line, newest first. In gdb you print it with `bt`, and it shows which of your lines called the function that crashed.
Bit, byte
A bit is a single 0 or 1. A byte is 8 bits and is the unit memory is counted in.
Block
Statements grouped between braces `{ }`. Everything inside the braces of main belongs to main.
bool
A type holding `true` or `false`. It needs `#include <stdbool.h>`.
break
A keyword that jumps out of a switch or leaves a loop at once. Without it in a switch, the code falls through.
Breakpoint
A function or line where the debugger pauses your program so you can look at it. In gdb you set one with `break main`.
Buffer overflow
Writing past the end of an array or heap block, which damages memory that belongs to something else. C doesn't check indexes, but AddressSanitizer reports it.
Bug
A mistake that makes a program do the wrong thing.

C

calloc
Like malloc, but it sets the memory to zero. `calloc(n, sizeof *qty)` reserves room for n elements, all zero.
Capacity
How many elements a heap array has room for, as opposed to how many are used (the count). When count reaches capacity, you double it with realloc.
Case-sensitive
Telling capitals from small letters. In C, `Printf` is not `printf`.
Cast
Converting a value to another type by writing the type in parentheses. `(double)total / people` makes the division keep its fraction.
char
A type holding one character, written in single quotes such as 'L'. Underneath it is a small number, and 'L' is 76.
Clang
A free C compiler that turns C source code into machine code. On a Mac, the `gcc` command actually runs Clang.
CMake
A build tool for managing the compilation of larger projects than `make` handles comfortably. It is widely used with C++.
Command
A typed instruction you give to the computer in a terminal. In examples, a line starting with `$ ` is a command you type after the `$`.
Command-line arguments
The words typed after a program's name. The till program receives menu.txt and order.txt this way, in argc and argv.
Comment
Text the compiler ignores, written as `// to end of line` or `/* ... */`. Comments are notes for people.
Comparison operators
Operators that compare two values and give 1 for true or 0 for false: `==` (equal, with two equals signs), `!=`, `<`, `>`, `<=` and `>=`. Don't confuse `==` with `=`, which stores.
Compiler
A program that turns source code into machine code and saves it as an executable. GCC and Clang are C compilers.
Compiler flags (-Wall -Wextra, -std=c17, -o, -c, -g)
Options given to gcc or clang. `-Wall -Wextra` turn on warnings, `-std=c17` picks the C17 language version (C23, from 2024, is the newest), `-o name` names the output file, `-c` compiles to an object file without linking, and `-g` adds debug information for gdb and lldb.
Compound assignment and ++ / --
Shortcuts that change a variable in place: `bags += 5` means `bags = bags + 5`, `bags++` adds 1 and `bags--` takes 1 away.
Condition
An expression, such as bags >= 10, that counts as true if it is nonzero and false if it is 0. if, while and for use conditions.
const
Marks a value the code may not change. A `const int *a` parameter promises the function only reads the array.
continue
A keyword that skips the rest of the current pass of a loop and goes on to the next pass.

D

Dangling pointer
A pointer to memory that is no longer yours, such as a freed block or a local variable of a function that has returned.
Debugger
A program that runs your program step by step and shows its variables, such as gdb or lldb.
Declaration
Telling the compiler a name and its type, such as `int bags;`.
Dereference
Putting `*` before a pointer to reach the variable it points to. `*p = 5` changes the variable p points at.
Designated initializer
A way to set a struct's members by name when creating it, such as `{.cents = 475}`, in any order. Any members you leave out start at zero.
diff
A command that compares two files and prints nothing when they match. The till's `make test` uses it to compare the receipt with expected.txt.
do ... while
A loop that checks its condition at the end, so its block always runs at least once.
double
A type for numbers with a decimal point, such as 0.75. It stores most decimals only approximately, so money is better kept in whole cents.
Double free
Calling free twice on the same block, which is undefined behavior and can crash.

E

Endless loop
A loop whose condition never becomes false. If a program seems stuck, press Ctrl+C.
EOF
The value getchar returns when the input has ended, such as a closed pipe or a file with nothing left. Loops check for it so they don't run forever.
Error, warning
An error is code the compiler can't understand, so you get no executable. A warning points to code that is legal but probably a mistake.
Escape sequence
A backslash code in a string for something you can't type directly, such as `\n` for a new line.
Executable
A file of machine code you can run like any other app. The compiler produces it from your source code.
Exit status
The number main returns to the system: 0 means it worked and anything else means something went wrong. stdlib.h names them EXIT_SUCCESS and EXIT_FAILURE.
Extension
An add-on that teaches VS Code a language. The C/C++ extension colors your code and underlines mistakes.

F

Fall-through
Running on into the next case's lines because a break is missing in a switch.
fgets
Reads a whole line into a buffer, never more than fits, and returns NULL at the end of input. It keeps the newline at the end of the line.
FILE *
A pointer to a struct that stdio.h uses to track an open file. fopen returns one, or NULL on failure.
File modes
The second argument of fopen: `"r"` reads, `"w"` writes (creating the file or emptying it) and `"a"` appends to the end.
Flag
An option for a command, usually starting with a dash, such as `-Wall` or `-o hello`.
fopen and fclose
fopen opens a file in mode "r", "w" or "a" and returns a FILE *, or NULL if it fails. fclose closes it and makes sure everything written reaches the disk.
Format specifier
A `%` code in a printf or scanf pattern that says how to handle the next value, such as `%d` for an int or `%.2f` for two decimals.
fprintf and fputs
fprintf is printf aimed at a file or stream, and fputs writes a string as it is. printf is really fprintf(stdout, ...).
free
Hands heap memory from malloc back. Free each block exactly once, then set the pointer to NULL.
Function
A named block of code that does one job. You call it by name wherever you need it.

G

GCC
The GNU Compiler Collection's C compiler, a free program that turns C source code into machine code. It is run with the `gcc` command.
gdb
The debugger used on Linux and Windows (MSYS2). It runs your program, stops at a crash or breakpoint and lets you inspect variables.
getchar
A function that reads one character from the input. It is often used in a loop to throw away the rest of a bad line of input.

H

Header
A .h file of declarations, pulled in by #include. stdio.h lists printf and other ready-made functions.
Heap
Memory you ask for with malloc, in any size, and give back with free. It stays yours even after the function that asked for it returns.
Hexadecimal
Base 16, with digits 0 to 9 and a to f. It's how %p prints addresses.

I

if / else if / else
A statement that runs a block only when its condition is true. else if and else add alternatives, and only the first true block runs.
Include guard
The #ifndef, #define and #endif lines in a header so that it's pasted in only once, avoiding errors such as conflicting types.
Index
An element's position in an array, counting from 0. C never checks that an index is inside the array.
Initialize
Giving a variable its first value when you declare it. An uninitialized C variable holds whatever was left in memory.
int
The type for whole numbers, 4 bytes here, up to about 2 billion.
Integer division
Using `/` on two whole numbers throws away the fraction, so 7 / 2 is 3. Cast one side to double to keep the fraction.

L

LeakSanitizer
The part of AddressSanitizer that reports memory leaks when the program ends, naming the line that called malloc.
Lifetime
How long a variable's memory belongs to it. Stack variables last until their function returns, and heap memory lasts until free.
Linker
The tool that joins object files and library functions such as printf into one executable. Its error 'undefined reference' means a function has no definition in the linked files.
lldb
The debugger on a Mac, from Xcode's Command Line Tools. Its commands are nearly the same as gdb's.
Local variable
A variable declared inside a function. It belongs to that function alone and is gone when the function returns.
Logical operators
Operators that combine true/false values: `&&` (and), `||` (or) and `!` (not). C treats 0 as false and any other number as true.
long
A type for larger whole numbers, 8 bytes on Linux and macOS but 4 on Windows. It prints with %ld.
Loop
Code that repeats. C has while, for and do ... while loops.

M

Machine code
The numbered instructions a processor runs directly. A compiler translates C into it.
main
The function every C program starts in. It returns an int exit status.
Make variables
Named values at the top of a Makefile, such as `CC = gcc` and `CFLAGS = ...`, used as `$(CC)` and `$(CFLAGS)` so you change a setting in one place.
make, Makefile
make is a tool that reads a file called Makefile and rebuilds only what changed. The file lists rules of target, prerequisites and a Tab-indented recipe.
malloc
Reserves that many bytes on the heap and returns a pointer to the first, or NULL if no memory is free. Always check the result, and free the block later.
man page
The manual page for a library function, shown in a Linux or Mac terminal with `man 3 printf`. Press q to leave.
Member
A named part of a struct, such as the cents of a menu Item. You reach it with a dot or ->.
Memory leak
Heap memory that is never freed. In a long-running program like a till, leaks pile up.
MSYS2
A Windows toolset that installs `gcc`, `make` and `gdb`, and provides a Unix-style terminal for running them. Its `gcc` has no sanitizers.

N

Newline
The `\n` character that ends a line of text. fgets keeps it at the end of the line it reads.
NULL
A special pointer value meaning points to nothing. Functions return it when there's nothing to point to, and dereferencing it crashes the program.
Null terminator
The `'\0'` character, with value 0, that ends every string. A char array needs one extra byte for it.

O

Object file
A compiled .o file: machine code that can't run on its own yet and still has to be linked.
Overflow
A result too big for its type. Overflowing a signed int is undefined behavior.

P

Parallel arrays
Arrays where the same index describes the same thing, such as codes[i] and prices[i] for one menu item. They are easy to get out of step, which is why structs come later.
Parameter
A variable in a function's definition that receives an argument. In line_total(int cents, int qty), cents and qty are the parameters.
Pass by value
A function gets a copy of each argument, so changing a parameter doesn't change the caller's variable. To change it, pass a pointer.
perror
Prints your text and the reason the last library call failed. After a failed fopen it might print `nosuch.txt: No such file or directory`.
Pointer
A variable that holds an address. `int *p` is a pointer to an int, and `*p` is the variable it points to.
Pointer arithmetic
Adding to a pointer to move by whole elements. `p + 1` points to the next int, and `p[i]` is shorthand for `*(p + i)`.
Precedence
Which operators are worked out first. `*`, `/` and `%` come before `+` and `-`, and parentheses let you choose.
Preprocessor
The step that handles lines starting with `#`, such as #include and #define, before compiling.
printf
Prints text to the screen. Format specifiers in its first argument are replaced by the values that follow.
Program, source code
A program is a list of instructions for a computer. Source code is the plain text you write them in.
Prototype
A function's first line plus a semicolon, placed before its first call so the compiler knows it. For example `int line_total(int cents, int qty);`.

R

RAII
Resource Acquisition Is Initialization: a C++ technique where a resource is cleaned up automatically when the object that owns it goes away. C has no such feature.
realloc
Resizes a heap block and keeps its contents, but may move it. Store its result in a temporary pointer and check for NULL, so a failure doesn't lose your only pointer to the old block.
Recipe
The Tab-indented command line in a Makefile rule that makes the target.
Remainder
What `%` gives: the amount left over after dividing, so `7 % 3` is 1. For example, `cents % 100` gives the cents part of a price.
Return type
The type of value a function gives back, written before its name. void means it returns nothing.

S

Sanitizer
Checks that the compiler builds into your program. They stop at the first bad access and report memory bugs and undefined behavior as they happen.
scanf
Reads values from the keyboard into variables, such as `scanf("%d", &qty)`. It returns how many values it read, so 1 means success.
Scope
The part of the code where a name can be used. A local variable's scope runs from its declaration to the end of its block.
Segmentation fault
A crash when the operating system stops a program that touched memory it may not use, often by dereferencing NULL.
size_t
The whole-number type for sizes, such as the result of sizeof or strlen. It prints with %zu.
sizeof
An operator that gives the size of a value or type in bytes. Dividing the array's size by one element's size gives the element count.
snprintf
Works like printf but writes into a char array. It never writes more than the buffer size and always ends with '\0', so it is the safe way to build or copy strings.
sscanf and fscanf
sscanf is scanf reading from a string, and fscanf reads from a file. Both return how many fields they filled, and a number after % limits how much they read.
Stack
Memory for local variables. Each function call gets fresh space there, which is taken back automatically when the function returns.
Standard streams
The three streams every program starts with: stdin for keyboard input, stdout for normal output and stderr for errors. Errors on stderr still show if the output goes to a file.
Statement
One instruction, ending in a semicolon.
strcpy
A function that copies a string but never checks the destination's size, so a long source writes past its end. `snprintf` is a safer way to copy.
strcspn
Counts the characters before the first match of given characters. `buf[strcspn(buf, "\n")] = '\0';` removes the newline fgets leaves.
String
Text in C: characters in a char array, ended by '\0'. You can't compare or copy it with == or =.
String literal
Text in double quotes in the code, which sits in memory the program may not change. Point at it with `const char *`.
strlen and strcmp
From string.h. strlen counts a string's characters before the '\0', and strcmp returns 0 when two strings are equal, so you write `strcmp(a, b) == 0`.
Struct
A type that groups named members into one value, such as a menu Item with a code, name and price.
switch
A statement that compares a whole number with fixed case values and runs the matching one. default runs when none match.

T

Target, prerequisite
In a Makefile rule, the target is the file the rule makes and the prerequisites are the files it needs. make rebuilds the target only if a prerequisite is newer.
Terminal
The window where you type commands instead of clicking.
toupper and isdigit
From ctype.h. toupper gives the capital of a letter, and isdigit is nonzero if a character is '0' to '9'.
Type
What kind of value a variable holds, and how many bytes it takes. Examples are int, double and char.
Typedef
A declaration that gives a type a new name. It lets a struct be called `Item` instead of `struct item`.

U

UBSan
A sanitizer switched on with `-fsanitize=undefined` that reports undefined behavior, such as signed integer overflow, as it happens.
Undefined behavior
Code the C standard gives no meaning, so anything may happen. Examples are overflowing an int, indexing past an array or using freed memory.
Undefined reference
A linker error meaning a function is called but defined in no file you linked. The fix is usually to add the missing .c or .o file.
Use after free
Using heap memory after free, when it may belong to something else. This is undefined behavior.

V

valgrind
A Linux tool that finds memory bugs similar to the sanitizers, without recompiling.
Variable
A named place in memory that holds a value of a given type.
void
A keyword meaning nothing. As a return type, the function gives back nothing, and in a parameter list it means the function takes nothing. `void *` is a general pointer type.
VS Code
A free code editor from Microsoft. With its C/C++ extension it colors your code and underlines mistakes.

W

WSL
Windows Subsystem for Linux, Microsoft's free way to run Ubuntu inside Windows. It gives Windows users access to Linux tools such as sanitizers.

X

Xcode Command Line Tools
Apple's developer tools on macOS, installed with `xcode-select --install`. They include Clang and lldb.