Skip to content

The C Programming Language

Everyone told you this was a bad idea, and yet here you are. Seriously, C is fifty-some odd years old, why would you want to learn C in 2024? That is not a question this text can answer in totality, but to start it’s not much of a stretch to say that the digital world still very much runs on C. The influence of the C language and its syntax is not only felt directly in digital devices the world over, but also in the way its syntax has inspired other languages like Perl, Java, JavaScript, Go, Rust, and more. C is a small, portable, and exceedingly permissive language. This makes C very flexible, but can also lead to deep frustrations with errors, styles and standards, and general readability. So why learn C when there are plenty of ergonomic, safer, and more modern language alternatives? C is considered a low-level language among the “high-level” (read human-friendly) languages. This means that C provides a good opportunity to get closer to how the computer actually operates. In short; C is a fantastic learning tool with plenty of real world examples.

This text doesn’t pretend to provide anything close to an authoritative or comprehensive guide on C, but rather presents the basics of a small, classic programming language as an introduction to all sorts of computer science subjects.

Install C

The C language installation will vary by system, so be sure to check with a local expert if any of the following installation tips do not work. While authoring this content I’m running MacOS (Monterey v12.6.7) on a (early) 2015 MacBook Pro. Until I get around to updating my machine (or if I decide to test on my intel-based Debian 12 setups) all content presented is tested on the Apple machine.

To get up and running on my Mac, all I had to do was install the xcode-select CLI tools. This includes both the C language itself and two compilers. To find out if you have these tools installed on your Mac already, use the following terminal command:

xcode-select --version

If a version appears, congrats! You have C! If the command doesn’t return definitive results, install x-code tools with the following command:

xcode-select --install

This triggers a flurry of activity, but when it’s all done, check the version again to make sure everything installed correctly.

Hello World

After ensuring that you have the language and a compiler installed, take em for a test drive! Create a file with a .c extension, such as HelloWorld.c. In that file, write the following program.

C
#include <stdio.h>
main() {
printf("Hello, world!\n");
}

After you save the file, use the terminal to navigate to the directory that the file is in (if you haven’t already) and compile the program using the following command:

Terminal window
gcc -o hello HelloWorld.c

The command invokes the GNU C Compiler (gcc) and uses the -o option to specify a name for the output executable. The example command names the executable “hello” instead of the default a.out.

If you haven’t totally botched it, you should get a successful compiler message. Now, the moment of truth; run the program by entering the file path:

Terminal window
./hello

The command should result in the terminal printing the following text:

Hello, world!

Congratulations! You’ve written, compiled, and run your first C program! Have a beer.

Translating code into executables