Introduction
Knowing a low level language is unavoidable. Understanding how to code in a language like C gives you a fundamental understanding of how computers work.
Why C?
C is the foundation of modern software. Operating systems, embedded systems, and performance-critical applications are often written in C. Learning C forces you to understand memory, data structures, and the hardware your code runs on. Other languages, like Python and Javascript, are written using the C Programming language. C is everywhere.
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}A Compiler
To write code in C, you'll need a compiler. A compiler is the program that takes the human readable and writeable code (C) and compiles it down to the language the computer speaks (machine code). Without a compiler, all we would have are text files. And that would be silly.
To install the compiler, use a package manager of your choosing.
Ubuntu/Debian (Linux)
Open your terminal and run the following:
sudo apt update
sudo apt install gcc build-essential
This installs the GNU C Compiler (gcc) and essential development tools like make and gdb.
For macOS
Use Homebrew to install the Xcode command line tools:
xcode-select --install
This installs clang, Apple’s C compiler, along with make and other developer tools.
To verify it's working, run:
clang --version
If you want to use gcc instead:
brew install gcc
Note: On macOS, gcc is usually just a wrapper around clang unless you're compiling with gcc-X specifically.
For Windows
Use WSL (Windows Subsystem for Linux) with Ubuntu:
- Install WSL: https://learn.microsoft.com/en-us/windows/wsl/install
- Open your WSL terminal and run:
sudo apt update
sudo apt install gcc build-essential
Alternatively, you can install MinGW or use a full Linux VM, but WSL is the most straightforward option.
C is a language that is unlike many other languages. C does not have a garbage collector, a live runtime, or any background safety system. It does exactly what you tell it to do.
Interpreted vs Compiled
C is a compiled language. When a C program is compiled, the compiler converts the human-readable code into machine code the processor understands.
This is different from interpreted languages like Python, where an interpreter (itself written in a compiled language) reads and runs your code line by line in a sandbox. Interpreted languages are generally safer and more portable but come with a performance cost.
Garbage Collection
C has no garbage collector. You allocate memory manually with malloc() and free it with free().
This has two effects:
- Pro: No overhead from garbage collection. Programs run faster and use less memory.
- Con: You must manually track memory usage. If you forget to
free()something, you leak memory. If youfree()the wrong thing, your program can crash or become vulnerable.
Languages like Go, Python, and Java handle this for you at runtime. C does not.
Strong vs Weak Typing
C is weakly typed. While types are defined at compile time, they can be changed later using type casting. This lets you do powerful things, like accessing raw memory, but it also allows bugs that would be caught in stricter languages.
Example in C:
int x = 10;
char *ptr = (char *)&x; // reinterpret int as a char pointerThis kind of behavior is not allowed in strongly typed languages like Rust.
Example of a Weakly Typed Language
Here's an example in JavaScript, a weakly typed language:
let x = "5"; // x is a string
let y = 2;
let result = x * y; // JavaScript converts "5" to 5 automatically
console.log(result); // Outputs: 10Even though x is a string, JavaScript implicitly converts it to a number when used with the multiplication operator. This kind of automatic type coercion is typical in weakly typed languages.
In contrast, a strongly typed language like Rust or Java would require explicit type conversion and would raise an error if mismatched types are used without conversion.
Conclusion
C gives you power, but it removes the guardrails. You get full control over how your code runs, but that control comes with responsibility. Once you learn C, you’ll understand how high-level languages work under the hood.
