C Programming Exam Cheat Sheet
Basic Concepts:
- Compiler: Converts code into machine language (e.g., GCC).
- Interpreter: Executes code line by line (e.g., Python).
- OS: Manages hardware/software, handles I/O, memory.
- Syntax vs Semantics: Syntax = rules, Semantics = meaning.
Number Systems:
- Decimal to Binary: divide by 2 repeatedly.
- Decimal to Hex: divide by 16 repeatedly.
- Example: 45 -> Binary: 101101, Hex: 2D
C Language Basics:
- Data Types: int, float, char, double.
- Operators: +, -, *, /, %, ==, !=, &&, ||, !
- Control: if, if-else, switch, for, while, do-while.
Arrays & Functions:
- Array: int arr[5] = {1,2,3,4,5};
- Function: return_type name(params) { ... }
- Recursion: A function calling itself.
Pointers:
- Pointer stores address: int *p = &x;
- Dereference: *p gives value at address.
File I/O:
- FILE *fp = fopen("file.txt", "r");
- fprintf(fp, ...), fscanf(fp, ...)
- fclose(fp); Modes: r, w, a
Structures & Unions:
- Structure: group of different data types.
- Union: shares memory among members.
- struct student { int id; char name[20]; };
Common Errors:
- Syntax Error: code rule mistake (e.g., missing ;)
- Logical Error: output is wrong despite no error.