An Overview of C

| 1 min read

Motivation

In this chapter, we provide a high level overview of C. We do that by showing representative example programs.

Saying Hello

In keeping with a programming tradition1, our first program will print the greeting “Hello, world!” to the screen. Here is one way to do it in C:

hello.c
#include <stdio.h>

int main()
{
    puts("Hello, world!"); // Greet the world!
    return 0;
}

And here’s how we would compile and run it on Linux:

$ gcc hello.c
$ ./a.out
Hello, world!

On Unix systems, the cc command invokes the C compiler. We pass the name of our source file hello.c to it. The compiler compiles our program and, if there are no errors in it, generates an equivalent machine language program, which is named a.out by default. We run our program on the next command line, which prints the expected greeting message.


  1. This tradition is usually attributed to the classic book on C programming, titled “The C Programming Language,” by Brian Kernighan and Dennis Ritchie. Arguably, it’s still the best introductory book you can find on C, as well as programming in general. ↩︎