C in 100 Seconds: Your First C Program | Episode 1
Video: C in 100 Seconds: Your First C Program | Episode 1 by Taught by Celeste AI - AI Coding Coach
Your First C Program
Six lines, one compile, one run.
#include <stdio.h>,int main,printf,return 0. The starting point for every C program ever.
C is fast, low-level, and everywhere — operating systems, databases, embedded systems, language runtimes. This series teaches it in 100-second episodes. We start where every C journey starts.
The full program
#include <stdio.h>
int main() {
printf("Welcome to C in 100s!\n");
return 0;
}
Six lines. Three things to learn — the include, main, and printf.
#include
#include <stdio.h>
#include is a preprocessor directive — it runs before the actual compiler does. It says "paste the contents of stdio.h here."
stdio.h is the standard input/output header. It declares functions like printf, scanf, fopen, fgets. Without including it, the compiler doesn't know what printf is.
The angle brackets <...> mean "look in the system include path." For your own headers, use double quotes: #include "myheader.h".
int main()
int main() {
// your code goes here
return 0;
}
Every C program starts at main. The OS calls main when your program runs.
int says main returns an integer — the exit status of the program. 0 traditionally means success; non-zero means an error. The shell can read this:
./hello
echo $? # prints 0 (last program's exit status)
The empty () means no parameters. The full version is int main(int argc, char *argv[]) — covered in episode 38 when we get to command-line arguments.
printf
printf("Welcome to C in 100s!\n");
printf is for formatted output. It writes a string to standard output (your terminal).
"Welcome to C in 100s!\n" is a string literal. The \n at the end is a newline — it moves the cursor to the next line. Without it, your terminal prompt would appear right after the text.
printf accepts format specifiers like %d (integer), %s (string), %f (float). We get to those in episode 3.
return 0
return 0;
Return from main with exit status 0 = success. Some compilers let you skip this — they implicitly add return 0 if you forget. But always write it. Explicit is better.
Compile and run
C is compiled — you turn source code into a native executable, then run it. With GCC:
gcc hello.c -o hello
./hello
gcc hello.c -o hello compiles hello.c into a binary named hello. The -o name flag sets the output filename; without it, GCC produces a.out (history: "assembler output").
./hello runs the binary. The ./ says "in this directory" — Linux/macOS won't search the current directory by default for security reasons.
You should see:
Welcome to C in 100s!
What just happened
- Preprocess — handle
#includeand macros.stdio.h's contents replace the include line. - Compile — turn C source into assembly, then machine code.
- Link — combine your code with the C runtime library (which contains the actual
printfimplementation). - Output — a single executable file.
For one-file programs, GCC does all four steps in one command. For larger projects, you split them up — covered in episode 41 (multi-file projects).
Other compilers
gcc— GNU Compiler Collection. The default on Linux.clang— LLVM-based, default on macOS and many BSDs.cl— Microsoft Visual C compiler on Windows.
For this series, any of them works. Sample commands and warnings might differ, but the C code is identical.
Common mistakes
Forgetting #include <stdio.h>. Compiler warning: "implicit declaration of function printf." Sometimes still links and runs, but undefined behavior on some platforms.
Forgetting the semicolon. printf(...) without ; doesn't compile. Every statement ends with ; in C.
Mixing print and printf. print is Python. C uses printf (note the trailing f).
Not running ./hello. Just typing hello searches your PATH for an installed binary, not the one you just compiled. Always ./ for local executables.
Using " inside a string. printf("She said "hi"") doesn't compile. Escape: "She said \"hi\"".
What's next
Episode 2: variables and types. int, float, char, double. The four foundational data types and their format specifiers.
Recap
#include <stdio.h> for printf. int main() is the entry point. printf("text\n") for output (with newline). return 0 for success. Compile with gcc file.c -o name; run with ./name. C is preprocessed → compiled → linked → executable. Every statement ends with ;.
Next episode: variables and types.