UTM CSSC

The C Programming Language

Prerequisites

  • Knowledge of basic programming concepts like variables, types, loops, lists/arrays, functions
  • Some beginner level programming experience

Intro to C

Motivation

As programmers, when making software, we are always limited by the language we're working with. In most cases, this is perfectly fine, but sometimes we need a bit more control over the machine that we're programming.

This requires a language that gives us full control over fine details of our program such as memory management and pointer manipulation (which we will talk about later).

As with any programming language we also would like this language to be simple, fast, and reliable.

What Is the C Programming Language?

The C Programming Language is one of the most widely used and influential programming languages of all time.

The language is used to develop programs in which speed, portability, and low-level control is required. For example, the hearts of the Windows, Mac, and Linux operating systems (called the kernel) are all written in C.

For a bit more background and a quick hello world tutorial in C check out this video!

Useful Concepts for Learning C

For this guide, we're assuming you're already familiar with the core concepts of programming and so we won't cover the basics of C here. We will instead focus on more advanced C concepts which will hopefully give you a headstart when working with C!

To learn the basics of C yourself checkout some suggested courses under 'Helpful Courses'.

Structs

We can use structs in C to combine many different pieces of data into one variable type like an integer or character type. The following video shows exactly how to use structs in C!

Pointers

Pointers are variables that hold the memory addresses of other variables in your code. These pointers can be used to access or change the values of the variables they 'point' to.

In C, We use pointers very often and so it's crucial to master pointers at both a basic and advanced level. The following video is a great explaination on how programs use memory and pointers.

Memory Management

Using pointers, we can allocate memory but what if we want to allocate specific amounts of memory? And what if we want to allocate memory at runtime? This requires memory allocation! The following video is a great intro to dynamic memory allocation in C.

File IO

When writing programs we will usually always want to save our output somewhere. Similarly, sometimes we may want to take in large inputs from files. This requires some interface that lets us read and write files. The following is a video that gives a really great intro to file IO in C.

Debugging

As with any programming endeavour, you will encounter many bugs. A great tool to debug programs in C is GDB (GNU Debugger). You will first have to install GDB. Once installed, you can watch this great video below to learn how to use GDB to debug your code!

You should also checkout the GDB cheatsheet under the 'Cheatsheets' section for even more GDB commands to play around with!

Helpful Courses

If you wish to take a full length C programming course we have picked out some our recommendations below!

Note that no course or guide will be completely comprehensive so we recommend going through EVERY unique topic from ALL the courses listed below to get as full of an understanding of C as possible.

Codecademy

Learn-C

Youtube Course

More Resources

Cheatsheet

Heres a cheatsheet from codecademy that includes a ton of common and useful C syntax.

Heres a useful cheatsheet for GDB

Documentation

Docs are extremely useful to have as reference whenever coding.