Hello World in C
Your first C program - the classic Hello World example with Docker setup
Every programming journey starts with Hello World. This example is particularly special in C - it’s the original Hello World, first appearing in the 1978 K&R book “The C Programming Language.”
The Code
Create a file named hello.c:
| |
Understanding the Code
#include <stdio.h>- Preprocessor directive that includes the standard I/O library, providing theprintffunction.int main(void)- The entry point of every C program.intmeans it returns an integer,voidmeans it takes no arguments.printf("Hello, World!\n")- Prints the string to standard output.\nis the newline character.return 0- Returns 0 to the operating system, indicating successful execution.
Running with Docker
The easiest way to run this without installing a C compiler locally:
| |
Running Locally
If you have GCC or Clang installed:
| |
On Windows with MinGW or MSVC:
| |
Expected Output
Hello, World!
Key Concepts
- C is compiled - Source code (
.c) is compiled to machine code (executable binary) - Preprocessing -
#includedirectives are processed before compilation - main() is special - Program execution begins at the
mainfunction - Return values matter - Returning 0 signals success to the operating system
- No garbage collection - C requires manual memory management (not needed for this simple example)
A Note on History
The original K&R Hello World looked slightly different:
| |
Modern C requires explicit int return type and recommends void for empty parameters. The modern style shown in our main example follows the C99/C11/C17/C23 standards.
Next Steps
Continue to Variables and Data Types to learn about C’s type system and memory layout.
Running Today
Last updated: