Skip to content
FLAVIO COPES
flaviocopes.com
2026

Introduction to the C Programming Language

By

Learn what C is, why it is still widely used, and how to compile and run your first C program with a modern Clang or GCC toolchain.

~~~

C is one of the best-known programming languages. It is often used in computer science courses, together with languages like Python and Java.

I remember it being my second programming language ever, after Pascal.

C is not just an academic language. It is used for operating systems, embedded devices, databases, compilers, and other software that needs direct access to memory and hardware.

The Linux kernel is mostly written in C. C code also runs on tiny microcontrollers and inside many of the tools we use every day. Pretty remarkable for a language created in the early 1970s.

When it was created, C was considered a high-level language because it was portable across machines. Today we take portability for granted. At the time, a language that could be implemented on different computers without hiding the machine underneath was a big step forward.

C implementations normally translate source code into machine code before the program runs. The exact process can involve preprocessing, compilation, assembly, and linking, but the compiler driver handles those steps for us.

C does not provide automatic garbage collection. When a program allocates memory dynamically, it is normally responsible for releasing that memory. This requires care, but it also gives the programmer a lot of control.

C does not hide the complexity and the capabilities of the machine underneath. You have a lot of power, once you know what you can do.

The current published revision of the language is ISO/IEC 9899:2024, commonly called C23. The examples in this tutorial use features supported by older C standards too.

Your first C program

Create a file called hello.c:

#include <stdio.h>

int main(void) {
  printf("Hello, World!\n");
  return 0;
}

The #include <stdio.h> line makes the declarations from the standard input/output header available. This includes printf().

main() is where a hosted C program starts. The void between parentheses says that this version of main() takes no arguments. Its return type is int.

printf() writes formatted output and returns the number of characters written, or a negative value if an error occurs. We ignore that return value here.

return 0 tells the environment that the program completed successfully.

Install a C compiler

A C compiler is not guaranteed to be installed by default.

On macOS, install Apple’s Command Line Tools with xcode-select --install. Apple documents this in Installing the command-line tools.

On Linux, install the compiler toolchain provided by your distribution. On Windows, you can use the C tools included with Visual Studio, or a Linux toolchain through WSL.

The command cc --version should tell you which compiler the generic cc command invokes. It will often be Clang or GCC.

Compile and run the program

From the folder containing hello.c, run:

cc -std=c17 -Wall -Wextra -Wpedantic hello.c -o hello

-std=c17 asks the compiler to use the C17 language standard. -Wall, -Wextra, and -Wpedantic enable useful diagnostics. GCC documents these options in its warning options reference.

If the compilation succeeds, the command creates an executable named hello. Run it:

./hello

You should see:

Hello, World!

The ./ prefix tells the shell to run the executable found in the current folder.

The size of the resulting file varies with the operating system, compiler, linked libraries, build settings, and executable format. C is useful on resource-constrained devices because it allows close control over memory and generated code, not because every C executable has a particular size.

Check out some of my other tutorials on C:

Tagged: C · All topics
~~~

Related posts about clang: