Learn C
#include "gettingstarted/first_program.h"

Writing and Running Your First Program in C

#concept

A C program is a plain text file ending in .c. Building it takes two steps: compile the source into a native executable with gcc, then run that executable. The compiler checks syntax and types before anything runs — errors mean no program is produced at all.

Every program needs exactly one main() function, the entry point the operating system calls. The classic first program prints Hello, World! with printf, proving the editor, compiler, and terminal all work end to end.

#how it works
1

Write the source file

Create hello.c in an editor. The name can be anything, but the .c extension marks it as C source.

2

Compile it

Run gcc hello.c -o hello -Wall. The compiler translates the source to machine code and writes the executable hello.

3

Run it

Run ./hello (or hello.exe on Windows). The OS loads the executable and calls your main() function.

4

Read compiler errors

Errors carry file names and line numbers — fix them and recompile, since nothing runs until the code is clean.

#example
#include <stdio.h>
 
int main(void) {
printf("Hello, World!\n");
return 0;
}
Output
Hello, World!
1#include <stdio.h> makes printf declared and usable.
2int main(void) is the mandatory entry point; the returned int becomes the program's exit code.
3printf writes the string plus newline, producing the single output line.
#use cases
Verifying a fresh compiler install produces working programs
The canonical first exercise in every C course and K&R itself
A minimal reproducible example when asking for help
A sanity check after switching compilers or machines

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C yourself — building beats watching.