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

  1. C Architecture, History & The GCC Compilation Pipeline
  2. Structure of a C Program: #include, main() & return Codes
  3. Standard I/O: printf(), Escape Sequences & Console Buffering
  4. Comments, Coding Style & Preprocessor Overview

2. Types, Variables & Format Specifiers

  1. Primitive Data Types & sizeof Operator
  2. Variables, Scope, const & Modern <stdint.h> Fixed-Width Types
  3. Format Specifiers & Field Width Alignment in printf()
  4. Type Conversions: Implicit Promotion vs Explicit Casting

3. Operators & Expression Evaluation

  1. Arithmetic, Modulo & Compound Assignment Operators
  2. Increment & Decrement: Prefix vs Postfix (++i vs i++)
  3. Relational & Logical Operators with Short-Circuit Evaluation
  4. Bitwise Operators (&, |, ^, ~, <<, >>) & Bitmasks

4. Control Flow & Branching

  1. if, else if, else Decision Structures & Nested Conditions
  2. Ternary Operator (?:) for Inline Conditional Expressions
  3. switch Statements, case Labels, break & Intentional Fallthrough
  4. Scope, Variable Shadowing & Storage Duration

5. Loops & Iteration Mechanics

  1. while & do-while Loops
  2. for Loops: Anatomy, Multiple Expressions & C99 Loop Declarations
  3. Nested Loops & Matrix Traversal Patterns
  4. Loop Control: break, continue & goto for Error Unwinding

6. Arrays & Matrix Operations

  1. One-Dimensional Arrays: Declaration, Bounds & Contiguous Memory
  2. Two-Dimensional Arrays, Matrices & Row-Major Storage
  3. Array Searching: Linear Search vs Binary Search
  4. Array Sorting: Bubble Sort, Selection Sort & Insertion Sort

7. Strings & String Handling (string.h)

  1. C Strings: Null-Terminated Character Arrays (\0) & Memory
  2. Core String Functions: strlen, strcpy, strcat & strcmp
  3. Safe String Handling: strncpy, strncat & snprintf() Bounds Enforcement
  4. String Parsing & Tokenization: sscanf() & strtok_r()

8. Pointers & Memory Addressing

  1. Pointers Fundamentals: Memory Addresses (&) & Dereferencing (*)
  2. Pointer Arithmetic & Array Navigation (ptr + i)
  3. Pass-by-Reference in C Using Pointers
  4. Void Pointers (void*), Null Pointers & Pointer-to-Pointer (**)

9. Functions, Recursion & Storage Classes

  1. Function Declarations, Prototypes & Header (.h) Separation
  2. Recursion & Call Stack Mechanics (Stack Overflow)
  3. Storage Classes: auto, static, extern & register
  4. Function Pointers & Callback Architecture

10. Structures (struct), Unions & typedef

  1. Structures (struct): User-Defined Types & Dot Operator (.)
  2. Pointers to Structs & The Arrow Operator (->)
  3. typedef, Clean Aliasing & Self-Referential Linked Lists
  4. Unions, Memory Overlap & Enums (enum)

11. Dynamic Memory Allocation (Heap)

  1. Heap Memory Management: malloc() & free() Lifecycles
  2. Zero-Initialized Memory (calloc) & Dynamic Resizing (realloc)
  3. Dangling Pointers, Memory Leaks & Valgrind Diagnostics
  4. Memory Manipulation: memcpy(), memmove(), memset() & memcmp()

12. File I/O, Preprocessor & System Programming

  1. File I/O Streams: fopen(), Mode Flags & fclose()
  2. Reading Text Files: fgets(), fgetc() & feof() Safety
  3. Binary File I/O: fread(), fwrite() & fseek()
  4. The Preprocessor: #define Macros, #ifdef & Conditional Compilation
  5. Command-Line Arguments: int main(int argc, char *argv[])
  6. 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 total
Check 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

logoblog

No comments:

Post a Comment

Please do not enter any spam link in the comment box.