Writing and Running Your First Program in C
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.
Write the source file
Create hello.c in an editor. The name can be anything, but the .c extension marks it as C source.
Compile it
Run gcc hello.c -o hello -Wall. The compiler translates the source to machine code and writes the executable hello.
Run it
Run ./hello (or hello.exe on Windows). The OS loads the executable and calls your main() function.
Read compiler errors
Errors carry file names and line numbers — fix them and recompile, since nothing runs until the code is clean.
#include <stdio.h> int main(void) { printf("Hello, World!\n"); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.