a blog about art, science & communication

Crash Course:: C Programming : I. What is C?

The C Programming Language was developed at Bell Labs, which is also where the Unix operating system was developed. Unix creators Ken Thompson and Dennis Ritchie wanted to port (rewrite) Unix so it would run on the new PDP-11 microcomputer (pictured in all it’s “micro” glory on the left). They were originally going to write the new Unix port in an existing language called B, but B didn’t allow for the usability of some of the PDP-11’s new features. To make use of everything the PDP-11 had to offer, most notably byte addressability (a small point that’ll become important later), Dennis Ritchie wrote a new programming language and called it C, as it was the language that came after B.

Unix, with a part of its programming written in C first, appeared in 1972. In 1973 structtypes (we’ll get to what exactly that means later) where added to C which made the language powerful enough that most of Unix was rewritten in C, making it one of the first Operating System not to be written in Assembly, a low-level language that looks a lot like machine code. By 1978 Dennis Ritchie and another Bell Labs programmer, Brian Kernighan, co-wrote the first edition of the The C Programming Language a textbook that’s still in print and considered by many to be the defacto textbook on C Programming. The C Programming Language also influenced many conventions now found in programming language technical writing, such as the “Hello, World!” introductory program.

Throughout the eighties and nineties several different versions of C were implemented on mainframes, microcontrollers and home computers, expandeding the languages popularity. Like all programming languages, C has gone through numerous standards revisions and changes. The current standard, published in 2011, is C11, which improves C’s compatibility with it’s sucessor C++ and Embedded C, a series of C extensions that are used to program microcontrollers.

Why Learn Such An Old Language?

Unlike other popular high-level languages, like Java or Python, C is designed to allow programmers low-level access to memory and additional libraries have been developed to extend that feature even further. This capability makes C enormously popular for coding applications that formerly involved machine instructions, like embedded systems, operating systems and supercomputers. Newer languages like C++ and Objective-C have augmented and extended the original C to include Object Orientated Programming methodologies. This kind of versatility has made C one of the most widely used Computer Programming Languages in the world, and since C has directly influenced almost every other popular language, from 20 year old Java to brand new languages like Swift and Go, it’s a good place to learn foundational programming concepts.

Yeah, but why should an ARTIST learn C?

If you’re an aspiring game designer C++ (an extension of C) is by far the most common language used in game development. If your a sculptor or new media artists looking to make artwork out of the Internet of Things, Embedded C is the standard language used to program microcontrollers and if you just want to straight up creative code on your laptop openFrameworks (built in C++) is an open source toolkit meant assist coders making creative projects.

Pretty awesome right?

Ok, now the downside. If you’ve previously coded in something like Python or Ruby the C Programming Language is gonna look clunky and unfriendly by comparison.

Basic Anatomy of a C Program

Below is a basic “Hello Word!” example demonstrating C’s syntax:

#include <stdio.h>
// Tells the computer to look for the standard C library

int main() { // See note in the text below

// print’s Hello, World! to the console
printf(“Hello, World!”);

// statement lets the computer know to exit the program.
return 0;

}

Note: All C Programs MUST have a main function and most, but not all, functions
need to return something, in this case main must return an integer value because the function main has been declared as an integer. Don’t worry about this detail too much, we’ll go into more detail in the lessons on data types and functions.

If you’d like to quickly see the above code in action, without needing to install a complier, type the code (you learn better when you type) it into the online C complier on JDoodle

You should see the output below:

Hello, World!

Did you get it running? Ok, if curly brackets aren’t a deal breaker for you continue reading my series on C Programming. In the next installment, we’ll look at Primative Data Types.