C Fundamentals

5 hours, 3 minutes CC
C Fundamentals

Course Description

Discover why C still powers the software world, from operating systems to databases. This course gives you hands-on experience with the fundamentals of C, including data types, control flow, low-level memory management, and system calls. You'll build a functioning HTTP server from scratch and walk away with a deeper understanding of how computers really work!

This course and others like it are available as part of our Frontend Masters video subscription.

Preview
Close

What They're Saying

This course is an absolute blast! It's rare to see a course that doesn't shy away from showing the danger in C while also keeping things fun.
Tarun Siva Sai Seelaboyina
Tarun Siva Sai Seelaboyina

Course Details

Published: June 9, 2025

Learning Paths

Learn Straight from the Experts Who Shape the Modern Web

Your Path to Senior Developer and Beyond
  • 200+ In-depth courses
  • 18 Learning Paths
  • Industry Leading Experts
  • Live Interactive Workshops

Table of Contents

Introduction

Section Duration: 23 minutes
  • Introduction
    Richard Feldman begins the course by looking at the wide range of modern languages and technologies that rely on the C programming language. C was released in 1972 and is still one of today's most commonly used languages.
  • Why C is Popular
    Richard describes what makes C so popular. The language provides the maximum possible performance while giving developers better ergonomics than assembly-style languages. It's also simpler to learn than other C-based languages like C++. Some alternatives to C are also discussed in this lesson.

Hello World in C

Section Duration: 36 minutes
  • Hello World in C
    Richard walks through a basic "hello world" example with C. Preprocessor directives, return types, and functions are introduced. The write method from the unistd.h library is called to print the string to the console. Richard also explains what happens at the hardware level when a C program is run.
  • Hello World using printf
    Richard refactors the "hello world" example using printf instead of write. The printf function is a wrapper around write, adding better ergonomics since the length of the string doesn't need to be calculated. The main function also returns 0, indicating the program was successfully completed.
  • Hello World in C Exercise
    Students are instructed to follow the steps in `exercises/1.c` and explore different use cases with the write and printf functions.

Building HTTP Responses

Section Duration: 40 minutes

Parsing HTTP Requests

Section Duration: 48 minutes
  • Functions & Iteration
    Richard introduces while and for loops and walks through the logic for extracting the path from a URL request. Variables for the starting and ending memory addresses are created, and for loops are used to iterate through the URL request and locate the path.
  • Copying Memory
    Richard introduces the memcpy function, which copies a block of memory from one location to another. The memcpy function could potentially introduce exploits or program segfaults since it could write into a memory space outside the URL request. Conditions could be added to ensure the length of the request memory block is longer than the file path being written into it.
  • Readonly vs Writable Memory
    Richard walks through the remaining implementation for the main function, which uses the returned path from the to_path function and prints it to the console. Using the "char *" notation for the request string will cause an error because C stores that string in read-only memory. Refactoring to bracket notation instructs the program to store the string in the application memory, allowing it to be mutated.
  • Parsing HTTP Requests Exercise
    Students are instructed to analyze the C program and fix the bugs described by the tests. The bugs include removing initial slashes from the path and ensuring the correct file path is specified.

File I/O & Memory Management

Section Duration: 53 minutes
  • File I/O
    Richard introduces the open and read functions for implementing file i/o. Both functions return "-1" if an error occurs while opening or reading a file. The read method writes the contents of the file into a memory buffer. Strategies for avoiding memory issues are discussed.
  • File Metadata
    Richard demonstrates how metadata can be extracted from a file. The stat struct contains properties like user ID, total size, and created/last-modified times. The fstat function is passed the file memory address and a reference to the metadata property to populate the values.
  • Memory Management in C
    Richard dives deeper into memory management in C. When functions return, memory for their variables is freed up. However, if memory addresses are returned from a function, that memory location may be overwritten later. The malloc function relieves some memory management issues by allocating long-lived memory chunks, but can introduce new issues with freeing up memory.
  • Stack vs. Heap Memory
    Richard explains the pros and cons of using stack memory versus managing memory on the heap. Heap memory can be more flexible, but is often slower than stack memory.
  • File I/O Exercise
    Students are instructed to use malloc and char* when declaring the buffer. The free function should also be added to avoid memory leaks. Finally, the program needs error handling for the open, stat, read, and malloc operations. Use the Linux man pages for error handling examples.

Network I/O

Section Duration: 43 minutes
  • Open Socket & Listen for Connections
    Richard discusses how to open a socket with C. The socket is bound to a port by passing the file descriptor, address structure, and size of the address. Once a socket is open, the program can listen for connections with the listen function, specifying the number of requests to queue before an error is thrown.
  • Read & Write to a Socket
    Richard demonstrates how to read a request out of the socket. A while loop continuously runs to ensure the program is listening for connections. The accept function is a blocking operation that waits for the next connection. Once a connection is received, the rest of the code in the loop executes, and the program waits for another connection.
  • Socket Exercise
    Students are instructed to refactor the HTTP server so that the server sends the error response codes through the socket back to the browser instead of the console.

Preprocessor & Platform-Specific Macros

Section Duration: 43 minutes
  • Bit Shifts
    Richard explains a few different ways the program could support additional file extensions. String comparisons can be costly, so casting the extensions to an integer and comparing those can increase the program's performance. A technique called bit shifting is used to help generate the integer values for each extension.
  • Preprocessor Macros
    Richard introduces #define, another preprocessor directive. Anything starting with a "#" is a preprocessor directive, and the define directive allows variables and functions to be defined and copied throughout the program before compile time. Functions defined this way are called preprocessor macros.
  • Platform Specific Macros
    Richard outlines some challenges with cross-platform development since operating systems may have different implementations of C functions. Target-specific preprocessor macros are available and behave like conditional statements, so these varying implementations can be handled within the application code instead of requiring separate codebase forks.
  • Web Server Image Support Exercise
    Students are instructed to implement the sendFile function so the contents of the HTML page are returned in the response from the server.

Wrapping Up

Section Duration: 12 minutes

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now