Hello World in C

Our first program will print the classic “hello world” message. Here’s the full source code.

#include <stdio.h>

int main() {
    printf("hello world\n");
    return 0;
}

To run the program, save the code in a file with a .c extension (e.g., hello-world.c) and use a C compiler to compile and run it.

$ gcc hello-world.c -o hello-world
$ ./hello-world
hello world

In C, we compile our programs into executable binaries. The compilation process is done using a C compiler like gcc (GNU Compiler Collection).

$ gcc hello-world.c -o hello-world
$ ls
hello-world    hello-world.c

We can then execute the compiled binary directly.

$ ./hello-world
hello world

Now that we can compile and run basic C programs, let’s learn more about the language.