Introduction

Short, annotated sample programs useful for a quick, example-based introduction to C programming. All the programs are complete and self-contained. To download a single program, visit its page and click "Show Code" in the upper right corner to display the pure C code corresponding to that example (right-click to save the file). To download code for all the programs, visit the downloads page.

Besides describing the programs, I also define some common terms used when talking about C programming. These definitions are both more and less than you need— more than you need to know in order to follow the program, and less than you need to know to fully appreciate the concepts. I hope to hit a middle ground with these definitions.

There's plenty of resources on the web that cover C much more thoroughly and carefully. Use this as just one resource.

main.c — the simplest C program in the world.

functions:main, printf, system, return
terms:function, declaration, argument, parameter, array, string, char, int, pointer

ifelse.c — taking different courses of action.

functions:if, else, <, <=, == (compare), !=, >, >=
terms:statement, expression, block, execute, operator, comparison operator

forloop.c — doing something over and over.

functions:for, = (assign), ++, --, +=, -=
terms:definition, variable, assign, increment, scope, loop, infinite loop

randarray.c — creating an array and selecting random elements from it.

functions:time, srand, rand, [] (array indexing), {,} (list)
terms:header file, initialize, type, seed, pseudo-random, index, garbage, crash

function.c — organizing your program using functions.

functions:() (function call)
terms:declaration, void, static, refactor, call a function, hard-coded, generalize