Skip to main content

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.
sizeofsizeof 运算符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 statementif 语句Executes a block only when the condition is true.
if-else statementif-else 语句Two-branch selection: one block for true, another for false.
if-else ladderif-else 阶梯Chain of else if clauses testing conditions top-to-bottom.
nested if嵌套 ifAn if (or if-else) placed inside another if or else block.
switch statementswitch 语句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 loopwhile 循环Entry-controlled; most general form of loop.
do-while loopdo-while 循环Exit-controlled; guarantees at least one execution of the body.
for loopfor 循环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.
breakbreak 语句Immediately exits the innermost enclosing loop (or switch).
continuecontinue 语句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 stringC字符串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.

PrecedenceOperatorDescriptionAssociativity
1++ --Suffix/postfix increment and decrementL-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 decrementR-L
+ -Unary plus and minus
! ~Logical NOT and bitwise NOT
(*type*)Cast
*Indirection (dereference)
&Address-of
sizeofSize-of
_AlignofAlignment requirement (C11)
3* / %Multiplication, division, and remainderL-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 conditionalR-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,CommaL-R

ASCII Printable Characters

DECOCTHEXBINSymbolDescription
324020100000SPSpace
334121100001!Exclamation mark
344222100010"Double quotes (or speech marks)
354323100011#Number sign
364424100100$Dollar
374525100101%Per cent sign
384626100110&Ampersand
394727100111'Single quote
405028101000(Open parenthesis (or open bracket)
415129101001)Close parenthesis (or close bracket)
42522A101010*Asterisk
43532B101011+Plus
44542C101100,Comma
45552D101101-Hyphen-minus
46562E101110.Period, dot or full stop
47572F101111/Slash or divide
4860301100000Zero
4961311100011One
5062321100102Two
5163331100113Three
5264341101004Four
5365351101015Five
5466361101106Six
5567371101117Seven
5670381110008Eight
5771391110019Nine
58723A111010:Colon
59733B111011;Semicolon
60743C111100<Less than (or open angled bracket)
61753D111101=Equals
62763E111110>Greater than (or close angled bracket)
63773F111111?Question mark
64100401000000@At sign
65101411000001AUppercase A
66102421000010BUppercase B
67103431000011CUppercase C
68104441000100DUppercase D
69105451000101EUppercase E
70106461000110FUppercase F
71107471000111GUppercase G
72110481001000HUppercase H
73111491001001IUppercase I
741124A1001010JUppercase J
751134B1001011KUppercase K
761144C1001100LUppercase L
771154D1001101MUppercase M
781164E1001110NUppercase N
791174F1001111OUppercase O
80120501010000PUppercase P
81121511010001QUppercase Q
82122521010010RUppercase R
83123531010011SUppercase S
84124541010100TUppercase T
85125551010101UUppercase U
86126561010110VUppercase V
87127571010111WUppercase W
88130581011000XUppercase X
89131591011001YUppercase Y
901325A1011010ZUppercase Z
911335B1011011[Opening bracket
921345C1011100\Backslash
931355D1011101]Closing bracket
941365E1011110^Caret - circumflex
951375F1011111_Underscore
96140601100000`Grave accent
97141611100001aLowercase a
98142621100010bLowercase b
99143631100011cLowercase c
100144641100100dLowercase d
101145651100101eLowercase e
102146661100110fLowercase f
103147671100111gLowercase g
104150681101000hLowercase h
105151691101001iLowercase i
1061526A1101010jLowercase j
1071536B1101011kLowercase k
1081546C1101100lLowercase l
1091556D1101101mLowercase m
1101566E1101110nLowercase n
1111576F1101111oLowercase o
112160701110000pLowercase p
113161711110001qLowercase q
114162721110010rLowercase r
115163731110011sLowercase s
116164741110100tLowercase t
117165751110101uLowercase u
118166761110110vLowercase v
119167771110111wLowercase w
120170781111000xLowercase x
121171791111001yLowercase y
1221727A1111010zLowercase z
1231737B1111011{Opening brace
1241747C1111100|Vertical bar
1251757D1111101}Closing brace
1261767E1111110~Equivalency sign - tilde
1271777F1111111DELDelete