C from the ground up
The small language under everything else
- Beginner
- 12 chapters
- 180 min read
Learn C by running it: main and printf, whole and decimal numbers, decisions, loops, functions and prototypes, arrays and sizeof, strings as char arrays, pointers and a swap through addresses, structs with typedef, malloc and free, the preprocessor, and a capstone that uses them all at once.
What You'll Learn
- Write and run a C program, and read what the compiler reports
- Store whole numbers and decimals, and know why integer division truncates
- Choose a path with if, else if and else, and compare values correctly
- Repeat work with for, while and do loops, and stop them on time
- Name work as functions, and promise the compiler a prototype
- Keep values in arrays, count them with sizeof, and walk them with a loop
- Treat text as char arrays and use strlen, strcmp and strcpy
- Hold addresses in pointers, follow them, and swap values through them
- Group fields into a struct and shorten the type with typedef
- Ask for memory at run time with malloc, use it like an array, and free it
- Name constants and small rules with the preprocessor and define
- Build a capstone: a struct, a dynamic list, functions and a report
Prerequisites
- No C at all — the course starts at the first include line
- Any experience with one other language makes the early chapters quicker, but none is assumed
Course Content
- 01Your first C programNot started
What C is, the shape every program shares, and your first run: two lines printed with printf and a value threaded into the text.
- 02Whole numbers and decimalsNot started
The two kinds of number C cares about, why dividing two whole numbers throws the fraction away, and how to print each kind cleanly.
- 03Decisions with if and elseNot started
Make a program choose a path: the if statement, the comparison operators, and the difference between one equals sign and two.
- 04Repeating work with loopsNot started
C has three loops and a reason to pick each one: for when you count, while when you wait, and do while when the body must run once.
- 05Functions and prototypesNot started
Name a piece of work and reuse it: how a function returns a value, why C wants to know about it in advance, and the prototype that says so.
- 06Arrays and sizeofNot started
Store many values of one type in a row, start counting at zero, walk the array with a loop, and let sizeof tell you how many there are.
- 07Strings as char arraysNot started
C has no string type: text is a char array ending in a zero. Meet strlen, strcmp and strcpy, the functions that know where the text ends.
- 08Pointers and addressesNot started
Every value lives at an address. A pointer holds one, the star follows it to the value, and that is how a function changes the caller's variable.
- 09Grouping values with structNot started
When values belong together, wrap them in a struct. Define a new type, name its fields, and give it a short alias with typedef.
- 10Memory you ask forNot started
Fixed arrays have a fixed size. malloc asks the system for memory while the program runs, and free hands it back when you are done.
- 11The preprocessor and defineNot started
Before C sees your file, the preprocessor edits it: pulling in headers and replacing names. define gives a value or a tiny rule a name.
- 12Putting it together: a rosterNot started
A capstone that uses the whole course at once: a struct type, memory asked for at run time, a function that reads it, and a final report.
