Review of Programming (C)
Key Terms
| Term | 中文 | Definition / Notes |
|---|---|---|
| IPO (Input–Process–Output) | 输入–处理–输出 | A conceptual model describing how a computer system receives data, manipulates it according to programmed instructions, and produces results. |
| compiler | 编译器 | A tool (e.g., GCC, or MSVC) that translates human-readable C source code into machine code that the CPU can execute directly. |
| preprocessor directive | 预处理器指令 | An instruction beginning with # that is processed before compilation proper; it typically inserts header file contents into the source, e.g., #include. |
| header file | 头文件 | A file containing declarations of library functions, e.g., stdio.h; included via #include so the compiler knows how to handle calls such as printf() and scanf(). |
main() function | 主函数 | The designated entry point of every C programme; execution begins at the first statement inside main(). |
printf() | 格式化输出函数 | A standard library function declared in <stdio.h> used to write formatted text to standard output (the console). |
scanf() | 格式化输入函数 | A standard library function declared in <stdio.h> used to read formatted input from standard input (the keyboard). |
| format specifier | 格式说明符 | A placeholder within a format string (e.g., %d for integers, %f for floating-point numbers, %s for strings) that indicates the type of data to be printed or read. |
| source file | 源文件 | A plain-text file with a .c extension containing C source code. |
| executable | 可执行文件 | The binary file produced by the compiler, which can be run directly by the operating system (OS). |
| variable | 变量 | A named storage location in memory that holds a value which may change during programme execution. Every variable has a type, a name, an address, and a value. |
| constant | 常量 | A value that cannot be altered after it is defined. May be established via #define (preprocessor macro) or const (typed, read-only variable). |
| literal | 字面量 | A fixed value written directly in the source code, such as 42 (integer literal), 3.14 (floating-point literal), 'A' (character literal), or "hello" (string literal). |
| identifier | 标识符 | The name given to a variable, function, or other user-defined entity. Must begin with a letter or underscore, followed by letters, digits, or underscores. Case-sensitive. |
| keyword (reserved word) | 关键字(保留字) | A word with a predefined meaning in C (e.g., int, return, while) that cannot be used as an identifier. |
| data type | 数据类型 | A classification that specifies the kind of value a variable can hold and the amount of memory allocated for it, e.g., int, float, double, char. |
| type modifier | 类型修饰符 | A qualifier that alters the size or sign of a base type: signed, unsigned, short, long. |
| declaration | 声明 | The act of informing the compiler of a variable's name and type, e.g., int age;. Memory is reserved but the value is indeterminate. |
| assignment | 赋值 | The act of storing a value in a previously declared variable, e.g., age = 19;. |
| initialisation | 初始化 | Declaring and assigning a value in a single statement, e.g., int age = 19;. |
| operator precedence | 运算符优先级 | The hierarchy that determines the order in which operators are evaluated within an expression. |
| associativity | 结合性 | The direction (left-to-right or right-to-left) in which operators of equal precedence are evaluated. |
| implicit conversion | 隐式类型转换 | An automatic type conversion performed by the compiler when operands of different types appear in the same expression (e.g., int promoted to float). |
| explicit casting | 显式类型转换(强制类型转换) | A programmer-directed type conversion using the cast operator, e.g., (int)3.14. |
| ASCII | 美国信息交换标准代码 | American Standard Code for Information Interchange — a character encoding in which each character is represented by a numeric value, e.g., 'A' = 65. |
sizeof | sizeof 运算符 | A compile-time operator that returns the size, in bytes, of a type or variable. |
| relational operator | 关系运算符 | Returns 1 (true) or 0 (false). Do not confuse with arithmetic operators. |
| logical operator | 逻辑运算符 | &&, ` |
| selection structure | 选择结构 | One of the three fundamental control structures (sequence, selection, repetition). |
| condition / Boolean expression | 条件 / 布尔表达式 | Any expression whose value is interpreted as true (non-zero) or false (zero). |
if statement | if 语句 | Executes a block only when the condition is true. |
if-else statement | if-else 语句 | Two-branch selection: one block for true, another for false. |
if-else ladder | if-else 阶梯 | Chain of else if clauses testing conditions top-to-bottom. |
nested if | 嵌套 if | An if (or if-else) placed inside another if or else block. |
switch statement | switch 语句 | Multi-way branch on an integer or character value. |
| fall-through | 穿透 | Default switch behaviour when break is omitted; execution continues into the next case. |
| short-circuit evaluation | 短路求值 | && stops if the left operand is false; ` |
| precedence | 优先级 | The order in which operators are evaluated, e.g., arithmetic > relational > logical > assignment. |
| associativity | 结合性 | Direction of evaluation for operators of equal precedence (left-to-right or right-to-left). |
| repetition structure / loop | 循环结构 | The third fundamental control structure; repeats a block while a condition holds. |
| entry-controlled loop | 入口控制循环 | Condition tested before the body executes (while, for). Body may execute zero times. |
| exit-controlled loop | 出口控制循环 | Condition tested after the body executes (do-while). Body always executes at least once. |
while loop | while 循环 | Entry-controlled; most general form of loop. |
do-while loop | do-while 循环 | Exit-controlled; guarantees at least one execution of the body. |
for loop | for 循环 | Entry-controlled; bundles initialisation, condition, and modification into one header. |
| counter-controlled loop | 计数器控制循环 | Iteration count is known in advance, e.g., repeat 10 times. |
| event-controlled / sentinel loop | 事件 / 哨兵控制循环 | Iteration ends when a special sentinel value is encountered; count is unknown in advance. |
| sentinel value | 哨兵值 | A marker value distinct from valid data that signals the end of input, e.g., −1. |
| compound assignment operator | 复合赋值运算符 | +=, -=, *=, /=, %= — shorthand for var = var op expr. |
| increment / decrement operator | 自增 / 自减运算符 | ++ / --. Prefix form modifies before use; postfix form modifies after use. |
| nested loop | 嵌套循环 | A loop placed inside the body of another loop; the inner loop completes all iterations per outer iteration. |
break | break 语句 | Immediately exits the innermost enclosing loop (or switch). |
continue | continue 语句 | Skips the remainder of the current iteration and jumps to the next condition check (or modification step in for). |
| infinite loop | 无限循环 | A loop whose condition never becomes false (e.g., while (1)); must contain a break or external termination. |
| parameterisation | 参数化 | Replacing hard-coded constants with variables so that a programme adapts to different inputs without rewriting. |
| array | 数组 | A fixed-size, contiguous block of elements of the same type. |
| index (subscript) | 下标/索引 | Starts from 0 in C, not 1. arr[0] is the first element if the array is declared as arr. |
| initialiser list | 初始化列表 | Brace-enclosed values, e.g. {1, 2, 3}. Partial initialisation zero-fills the remainder. |
| contiguous memory | 连续内存 | Array elements are stored adjacently; address of element i = base + i × element size. |
| null terminator | 空字符 / 终止符 | '\0' marks the end of a C string; a char array of n visible characters requires n + 1 bytes. |
| C string | C字符串 | A char array terminated by '\0'; not a first-class type but a convention. |
fgets() | – | Reads up to size − 1 characters including spaces; safer than gets(), which is deprecated. |
| two-dimensional array | 二维数组 | An array of arrays; stored in row-major order in memory. |
| row-major order | 行优先存储 | Elements of the same row are contiguous in memory. |
| bubble sort | 冒泡排序 | An O(n²) comparison-based sorting algorithm that repeatedly swaps adjacent elements. |
| sentinel value | 哨兵值 | A special value (e.g. −1) used to signal the end of input rather than specifying a fixed count. |
| function declaration (prototype) | 函数声明(原型) | Tells the compiler about name, return type, and parameter types; ends with ;; no body. |
| function definition | 函数定义 | Contains the actual body (implementation). Must match its prototype. |
| function call (invocation) | 函数调用 | The point in code where execution transfers to the function. |
| parameter (formal parameter) | 形式参数 / 型参 | The variable names listed in the function header. |
| argument (actual parameter) | 实际参数 / 值参 | The concrete values or expressions supplied at the call site. Easily confused with parameter. |
| return type | 返回类型 | The data type of the value the function hands back; void if none. |
| pass by value | 值传递 | The default in C for scalar types—a copy is passed. |
| pass by reference | 引用传递 | In C, achieved via pointers. Arrays are effectively passed by reference. |
| stack frame | 栈帧 | A block of memory on the call stack holding a function's local variables, parameters, and return address. |
| recursion | 递归 | A function that calls itself; must have a base case to terminate. |
| base case | 基线条件 | The condition under which a recursive function stops calling itself. |
| scope | 作用域 | The region of source code in which a variable is visible. |
| local variable | 局部变量 | Declared inside a function or block; visible only there. |
| global variable | 全局变量 | Declared outside all functions; visible to every function that follows its declaration. |
| library function | 库函数 | Pre-built functions provided by the C Standard Library, e.g. printf(), sqrt(). |
| user-defined function | 用户自定义函数 | Functions written by the programmer. |
| modular design | 模块化设计 | Structuring a programme as a collection of independent, well-defined modules (functions). |
| pointer | 指针 | A variable whose value is a memory address. |
address-of operator & | 取地址运算符 | Yields the address of its operand; do not confuse with the bitwise AND &. |
dereference operator * | 解引用运算符 | Accesses the value stored at the address held by a pointer; same symbol as the declaration *, but used in a different syntactic position. |
NULL pointer | 空指针 | A pointer that points to nothing; defined in <stdio.h> and <stdlib.h>. Dereferencing NULL causes undefined behaviour. |
| pointer arithmetic | 指针算术 | Adding or subtracting an integer to/from a pointer; the offset is automatically scaled by sizeof the pointed-to type. |
malloc() / free() | 动态内存分配 / 释放 | Library functions in <stdlib.h> for heap allocation. Always check the return value of malloc() and always call free() when the memory is no longer needed. |
| pointer to pointer | 二级指针 | A pointer that stores the address of another pointer, e.g. int **pp;. |
| function pointer | 函数指针 | A pointer that stores the address of a function; enables indirect (dynamic) function calls. Syntax: return_type (*name)(param_list);. |
| dangling pointer | 悬空指针 | A pointer that refers to memory that has been freed or has gone out of scope; dereferencing it is undefined behaviour. |
| bit | 比特(位) | The smallest unit of data: 0 or 1. |
| byte | 字节 | = 8 bits. |
| Most Significant Bit (MSB) | 最高有效位 | The leftmost bit; in a signed integer it is the sign bit. |
| Least Significant Bit (LSB) | 最低有效位 | The rightmost bit; determines whether a number is odd or even. |
| numeral system (radix/base) | 进制(基数) | A writing system for numbers; common bases are 2, 8, 10, 16. |
| binary (Base-2) | 二进制 | Digits 0–1. C prefix: 0b (GCC/Clang extension) or no standard prefix. |
| octal (Base-8) | 八进制 | Digits 0–7. C prefix: 0 (leading zero). |
| hexadecimal (Base-16) | 十六进制 | Digits 0–9, A–F. C prefix: 0x or 0X. |
| two's complement | 补码 | The standard signed-integer representation: invert all bits and add 1. |
bitwise AND (&) | 按位与 | Result bit is 1 only when both operand bits are 1. |
| bitwise OR (` | `) | 按位或 |
bitwise XOR (^) | 按位异或 | Result bit is 1 when the operand bits differ. Easily confused with exponentiation (which C does not have). |
bitwise NOT (~) | 按位取反 | Flips every bit; unary operator. |
left shift (<<) | 左移 | Shifts bits leftward, filling with 0 on the right. Equivalent to multiplication by 2ⁿ. |
right shift (>>) | 右移 | Shifts bits rightward. For unsigned types, fills with 0 (logical shift); for signed types, typically fills with the sign bit (arithmetic shift — implementation-defined). |
| bit mask | 位掩码 | A value used with a bitwise operator to select, set, clear, or toggle specific bits. |
| set a bit | 置位 | Force a bit to 1 using OR with a mask. |
| clear a bit | 清位 | Force a bit to 0 using AND with the complement of a mask. |
| toggle a bit | 翻转位 | Flip a bit using XOR with a mask. |
struct | 结构体 | A user-defined composite type that groups variables of different types under one name. Members are accessed with . (by value) or -> (by pointer). |
typedef | 类型别名 | Creates an alias for an existing type; commonly used with struct to avoid repeating the struct keyword. |
union | 联合体 | Like a struct, but all members share the same memory; only one member is valid at any time. The size of a union equals the size of its largest member. |
enum | 枚举 | Defines a set of named integer constants; by default values start at 0 and increment by 1, but may be set explicitly. |
| file stream | 文件流 | An abstraction provided by <stdio.h> for sequential reading or writing of data; represented by the FILE * type. |
fopen() / fclose() | 打开 / 关闭文件 | fopen(path, mode) returns a FILE * (or NULL on failure); fclose(fp) flushes the buffer and releases the resource. |
| text mode | 文本模式 | Human-readable characters; modes "r", "w", "a", etc. Newline translation may occur on some platforms. |
| binary mode | 二进制模式 | Raw bytes preserving the exact memory layout; modes "rb", "wb", "ab", etc. Essential for non-text data such as images, audio, or struct records. |
fprintf() / fscanf() | 格式化文件写 / 读 | Formatted I/O analogous to printf() / scanf(), but operating on a file stream rather than stdout / stdin. |
fwrite() / fread() | 二进制写 / 读 | Transfer raw blocks of bytes between memory and a file; parameters are: data pointer, element size, element count, stream. |
perror() | 打印系统错误 | Prints a user-supplied prefix followed by a colon and the system error message corresponding to the current value of errno. |
EOF | 文件结束标志 | A macro (typically −1) returned by I/O functions to signal that the end of the file has been reached or that an error occurred. |
argc / argv | 命令行参数 | argc is the count of command-line tokens (including the programme name); argv is an array of C strings containing those tokens. |
Reserved Keywords
The following identifiers are reserved and may not be used as variable or function names. Keywords marked with a standard version were introduced in that revision of the language.
auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, inline (C99), int, long, register, restrict (C99), return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.
C Operator Precedence
The following table lists the precedence and associativity of C operators. Operators are listed top to bottom, in descending precedence.
See details here.
| Precedence | Operator | Description | Associativity |
|---|---|---|---|
| 1 | ++ -- | Suffix/postfix increment and decrement | L-R |
() | Function call | ||
[] | Array subscripting | ||
. | Structure and union member access | ||
-> | Structure and union member access through pointer | ||
(*type*){*list*} | Compound literal (C99) | ||
| 2 | ++ -- | Prefix increment and decrement | R-L |
+ - | Unary plus and minus | ||
! ~ | Logical NOT and bitwise NOT | ||
(*type*) | Cast | ||
* | Indirection (dereference) | ||
& | Address-of | ||
sizeof | Size-of | ||
_Alignof | Alignment requirement (C11) | ||
| 3 | * / % | Multiplication, division, and remainder | L-R |
| 4 | + - | Addition and subtraction | |
| 5 | << >> | Bitwise left shift and right shift | |
| 6 | < <= | For relational operators < and ≤ respectively | |
> >= | For relational operators > and ≥ respectively | ||
| 7 | == != | For relational = and ≠ respectively | |
| 8 | & | Bitwise AND | |
| 9 | ^ | Bitwise XOR (exclusive or) | |
| 10 | | | Bitwise OR (inclusive or) | |
| 11 | && | Logical AND | |
| 12 | || | Logical OR | |
| 13 | ?: | Ternary conditional | R-L |
| 14 | = | Simple assignment | |
+= -= | Assignment by sum and difference | ||
*= /= %= | Assignment by product, quotient, and remainder | ||
<<= >>= | Assignment by bitwise left shift and right shift | ||
&= ^= |= | Assignment by bitwise AND, XOR, and OR | ||
| 15 | , | Comma | L-R |
ASCII Printable Characters
| DEC | OCT | HEX | BIN | Symbol | Description |
|---|---|---|---|---|---|
| 32 | 40 | 20 | 100000 | SP | Space |
| 33 | 41 | 21 | 100001 | ! | Exclamation mark |
| 34 | 42 | 22 | 100010 | " | Double quotes (or speech marks) |
| 35 | 43 | 23 | 100011 | # | Number sign |
| 36 | 44 | 24 | 100100 | $ | Dollar |
| 37 | 45 | 25 | 100101 | % | Per cent sign |
| 38 | 46 | 26 | 100110 | & | Ampersand |
| 39 | 47 | 27 | 100111 | ' | Single quote |
| 40 | 50 | 28 | 101000 | ( | Open parenthesis (or open bracket) |
| 41 | 51 | 29 | 101001 | ) | Close parenthesis (or close bracket) |
| 42 | 52 | 2A | 101010 | * | Asterisk |
| 43 | 53 | 2B | 101011 | + | Plus |
| 44 | 54 | 2C | 101100 | , | Comma |
| 45 | 55 | 2D | 101101 | - | Hyphen-minus |
| 46 | 56 | 2E | 101110 | . | Period, dot or full stop |
| 47 | 57 | 2F | 101111 | / | Slash or divide |
| 48 | 60 | 30 | 110000 | 0 | Zero |
| 49 | 61 | 31 | 110001 | 1 | One |
| 50 | 62 | 32 | 110010 | 2 | Two |
| 51 | 63 | 33 | 110011 | 3 | Three |
| 52 | 64 | 34 | 110100 | 4 | Four |
| 53 | 65 | 35 | 110101 | 5 | Five |
| 54 | 66 | 36 | 110110 | 6 | Six |
| 55 | 67 | 37 | 110111 | 7 | Seven |
| 56 | 70 | 38 | 111000 | 8 | Eight |
| 57 | 71 | 39 | 111001 | 9 | Nine |
| 58 | 72 | 3A | 111010 | : | Colon |
| 59 | 73 | 3B | 111011 | ; | Semicolon |
| 60 | 74 | 3C | 111100 | < | Less than (or open angled bracket) |
| 61 | 75 | 3D | 111101 | = | Equals |
| 62 | 76 | 3E | 111110 | > | Greater than (or close angled bracket) |
| 63 | 77 | 3F | 111111 | ? | Question mark |
| 64 | 100 | 40 | 1000000 | @ | At sign |
| 65 | 101 | 41 | 1000001 | A | Uppercase A |
| 66 | 102 | 42 | 1000010 | B | Uppercase B |
| 67 | 103 | 43 | 1000011 | C | Uppercase C |
| 68 | 104 | 44 | 1000100 | D | Uppercase D |
| 69 | 105 | 45 | 1000101 | E | Uppercase E |
| 70 | 106 | 46 | 1000110 | F | Uppercase F |
| 71 | 107 | 47 | 1000111 | G | Uppercase G |
| 72 | 110 | 48 | 1001000 | H | Uppercase H |
| 73 | 111 | 49 | 1001001 | I | Uppercase I |
| 74 | 112 | 4A | 1001010 | J | Uppercase J |
| 75 | 113 | 4B | 1001011 | K | Uppercase K |
| 76 | 114 | 4C | 1001100 | L | Uppercase L |
| 77 | 115 | 4D | 1001101 | M | Uppercase M |
| 78 | 116 | 4E | 1001110 | N | Uppercase N |
| 79 | 117 | 4F | 1001111 | O | Uppercase O |
| 80 | 120 | 50 | 1010000 | P | Uppercase P |
| 81 | 121 | 51 | 1010001 | Q | Uppercase Q |
| 82 | 122 | 52 | 1010010 | R | Uppercase R |
| 83 | 123 | 53 | 1010011 | S | Uppercase S |
| 84 | 124 | 54 | 1010100 | T | Uppercase T |
| 85 | 125 | 55 | 1010101 | U | Uppercase U |
| 86 | 126 | 56 | 1010110 | V | Uppercase V |
| 87 | 127 | 57 | 1010111 | W | Uppercase W |
| 88 | 130 | 58 | 1011000 | X | Uppercase X |
| 89 | 131 | 59 | 1011001 | Y | Uppercase Y |
| 90 | 132 | 5A | 1011010 | Z | Uppercase Z |
| 91 | 133 | 5B | 1011011 | [ | Opening bracket |
| 92 | 134 | 5C | 1011100 | \ | Backslash |
| 93 | 135 | 5D | 1011101 | ] | Closing bracket |
| 94 | 136 | 5E | 1011110 | ^ | Caret - circumflex |
| 95 | 137 | 5F | 1011111 | _ | Underscore |
| 96 | 140 | 60 | 1100000 | ` | Grave accent |
| 97 | 141 | 61 | 1100001 | a | Lowercase a |
| 98 | 142 | 62 | 1100010 | b | Lowercase b |
| 99 | 143 | 63 | 1100011 | c | Lowercase c |
| 100 | 144 | 64 | 1100100 | d | Lowercase d |
| 101 | 145 | 65 | 1100101 | e | Lowercase e |
| 102 | 146 | 66 | 1100110 | f | Lowercase f |
| 103 | 147 | 67 | 1100111 | g | Lowercase g |
| 104 | 150 | 68 | 1101000 | h | Lowercase h |
| 105 | 151 | 69 | 1101001 | i | Lowercase i |
| 106 | 152 | 6A | 1101010 | j | Lowercase j |
| 107 | 153 | 6B | 1101011 | k | Lowercase k |
| 108 | 154 | 6C | 1101100 | l | Lowercase l |
| 109 | 155 | 6D | 1101101 | m | Lowercase m |
| 110 | 156 | 6E | 1101110 | n | Lowercase n |
| 111 | 157 | 6F | 1101111 | o | Lowercase o |
| 112 | 160 | 70 | 1110000 | p | Lowercase p |
| 113 | 161 | 71 | 1110001 | q | Lowercase q |
| 114 | 162 | 72 | 1110010 | r | Lowercase r |
| 115 | 163 | 73 | 1110011 | s | Lowercase s |
| 116 | 164 | 74 | 1110100 | t | Lowercase t |
| 117 | 165 | 75 | 1110101 | u | Lowercase u |
| 118 | 166 | 76 | 1110110 | v | Lowercase v |
| 119 | 167 | 77 | 1110111 | w | Lowercase w |
| 120 | 170 | 78 | 1111000 | x | Lowercase x |
| 121 | 171 | 79 | 1111001 | y | Lowercase y |
| 122 | 172 | 7A | 1111010 | z | Lowercase z |
| 123 | 173 | 7B | 1111011 | { | Opening brace |
| 124 | 174 | 7C | 1111100 | | | Vertical bar |
| 125 | 175 | 7D | 1111101 | } | Closing brace |
| 126 | 176 | 7E | 1111110 | ~ | Equivalency sign - tilde |
| 127 | 177 | 7F | 1111111 | DEL | Delete |