Learn compiled programming, explicit types, pointers and memory management.
Before starting: Files, terminal commands, and a C compiler.
Practice project: Build a text-file score reader that checks every resource operation.
1. C Architecture, Compilation & Setup
- C Architecture, History & The GCC Compilation Pipeline
- Structure of a C Program: #include, main() & return Codes
- Standard I/O: printf(), Escape Sequences & Console Buffering
- Comments, Coding Style & Preprocessor Overview
2. Types, Variables & Format Specifiers
- Primitive Data Types & sizeof Operator
- Variables, Scope, const & Modern <stdint.h> Fixed-Width Types
- Format Specifiers & Field Width Alignment in printf()
- Type Conversions: Implicit Promotion vs Explicit Casting
3. Operators & Expression Evaluation
- Arithmetic, Modulo & Compound Assignment Operators
- Increment & Decrement: Prefix vs Postfix (++i vs i++)
- Relational & Logical Operators with Short-Circuit Evaluation
- Bitwise Operators (&, |, ^, ~, <<, >>) & Bitmasks
4. Control Flow & Branching
- if, else if, else Decision Structures & Nested Conditions
- Ternary Operator (?:) for Inline Conditional Expressions
- switch Statements, case Labels, break & Intentional Fallthrough
- Scope, Variable Shadowing & Storage Duration
5. Loops & Iteration Mechanics
- while & do-while Loops
- for Loops: Anatomy, Multiple Expressions & C99 Loop Declarations
- Nested Loops & Matrix Traversal Patterns
- Loop Control: break, continue & goto for Error Unwinding
6. Arrays & Matrix Operations
- One-Dimensional Arrays: Declaration, Bounds & Contiguous Memory
- Two-Dimensional Arrays, Matrices & Row-Major Storage
- Array Searching: Linear Search vs Binary Search
- Array Sorting: Bubble Sort, Selection Sort & Insertion Sort
7. Strings & String Handling (string.h)
- C Strings: Null-Terminated Character Arrays (\0) & Memory
- Core String Functions: strlen, strcpy, strcat & strcmp
- Safe String Handling: strncpy, strncat & snprintf() Bounds Enforcement
- String Parsing & Tokenization: sscanf() & strtok_r()
8. Pointers & Memory Addressing
- Pointers Fundamentals: Memory Addresses (&) & Dereferencing (*)
- Pointer Arithmetic & Array Navigation (ptr + i)
- Pass-by-Reference in C Using Pointers
- Void Pointers (void*), Null Pointers & Pointer-to-Pointer (**)
9. Functions, Recursion & Storage Classes
- Function Declarations, Prototypes & Header (.h) Separation
- Recursion & Call Stack Mechanics (Stack Overflow)
- Storage Classes: auto, static, extern & register
- Function Pointers & Callback Architecture
10. Structures (struct), Unions & typedef
- Structures (struct): User-Defined Types & Dot Operator (.)
- Pointers to Structs & The Arrow Operator (->)
- typedef, Clean Aliasing & Self-Referential Linked Lists
- Unions, Memory Overlap & Enums (enum)
11. Dynamic Memory Allocation (Heap)
- Heap Memory Management: malloc() & free() Lifecycles
- Zero-Initialized Memory (calloc) & Dynamic Resizing (realloc)
- Dangling Pointers, Memory Leaks & Valgrind Diagnostics
- Memory Manipulation: memcpy(), memmove(), memset() & memcmp()
12. File I/O, Preprocessor & System Programming
- File I/O Streams: fopen(), Mode Flags & fclose()
- Reading Text Files: fgets(), fgetc() & feof() Safety
- Binary File I/O: fread(), fwrite() & fseek()
- The Preprocessor: #define Macros, #ifdef & Conditional Compilation
- Command-Line Arguments: int main(int argc, char *argv[])
- Variable Argument Lists (<stdarg.h>) & va_list Mechanics
Trace changing state and check loop boundaries
A trace table records the state after each statement. It helps distinguish an incorrect algorithm from a syntax mistake. Write the input contract first: this example accepts a list of numbers and returns their sum. The initial total is zero, so an empty list returns zero.
Paper trace first; pseudocode is not executable. Use your chosen language compiler or interpreter for the implementation.
PSEUDOCODE — translate before running
total ← 0
FOR EACH value IN values
total ← total + value
RETURN totalCheck the output
[2, -1, 4] → 5
[] → 0
[7] → 7
The loop must process each element exactly once.Trace [-3, 3] without running code. Then implement and test it. Explain why starting at the second element loses data. Reject non-number input or explicitly document that it is outside the input contract.
Check C input and file errors
Library calls can fail even when the program compiles. Inspect a return value before using the resource it represents. A failed fopen returns a null pointer; passing it to file-reading functions is invalid. This example reports the operating-system error and exits unsuccessfully. It closes the stream on the successful path.
Hosted C17 environment with GCC or Clang
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *file = fopen("score.txt", "r");
if (file == NULL) {
perror("score.txt");
return EXIT_FAILURE;
}
if (fclose(file) == EOF) {
perror("closing score.txt");
return EXIT_FAILURE;
}
puts("File opened and closed");
return EXIT_SUCCESS;
}Check the output
With a readable file: File opened and closed. Without it: an error message on stderr; wording depends on the operating system.Use fgets to read one line. Distinguish end-of-file from a read error with ferror before deciding which message to display.
Open the C learning path on DevStudyHub · Play coding games on this blog
No comments:
Post a Comment
Please do not enter any spam link in the comment box.