C Refresher

Introduction to C

This refresher covers the C concepts you'll encounter throughout the workshop. ESP-IDF firmware is written in C, so comfort with these fundamentals is essential.

No prior C experience? This page is written for you. We start from the very basics — what a program is, how code runs, and build up step by step. If you've only written "Hello World" in school, you're in the right place.

If you're already comfortable with C, you can skim this section or jump straight to the Build Systems section.


What Is a C Program?

A C program is a list of instructions that tells the computer what to do, step by step. The computer reads your code from top to bottom and executes each line one at a time.

Think of it like a recipe:

  1. Get the ingredients → declare variables (your data)
  2. Follow the steps → write statements (your logic)
  3. Serve the dish → produce output (your result)

Your First C Program

c
1#include <stdio.h> // Include the standard I/O library (for printf)
2
3int main(void) { // Every C program starts here — the "main" function
4 printf("Hello, World!\n"); // Print a message to the screen
5 return 0; // Tell the OS: "everything went OK"
6}

Let's break this down line by line:

LineWhat It DoesWhy It Matters
#include <stdio.h>Loads the "standard input/output" libraryWithout this, printf doesn't exist
int main(void)The entry point — where execution beginsEvery C program must have a main function
printf("Hello, World!\n")Prints text to the screen\n means "new line" — like pressing Enter
return 0Exits the program with success code0 = success, anything else = error

Semicolons are mandatory

Every statement in C must end with a semicolon ;. Forgetting it is the #1 beginner mistake. The compiler will give you a confusing error if you miss one.


Comments — Writing Notes in Your Code

Comments allow you to leave notes for yourself or other developers. The compiler completely ignores them.

c
1// This is a single-line comment
2// The compiler ignores comments — they're for humans
3
4/*
5 This is a multi-line comment.
6 Useful for longer explanations.
7 The compiler ignores everything between the slash-star and star-slash.
8*/
9
10// USE COMMENTS TO:
11// 1. Explain WHY you're doing something (not WHAT — the code shows what)
12// 2. Mark sections of your code
13// 3. Temporarily disable code while debugging
Previous
Variables & Loops