Category Archives: C Programming

Dynamic Memory in C (malloc, calloc, realloc, free)

Let’s take a look at the four methods that allow us to utilize dynamic memory in C. Dynamic memory just means we are using memory on the heap, instead of on the stack. Why would you want to use dynamic memory? You might want to create a variable or object that persists beyond the scope […]

Declaring Variables in Switch Statements

There you are, happily programming away, when suddenly you get a compile error: error: jump to case label error: crosses initialization of ‘int x’ “Huh?” You say, peering at the computer screen. Your code looks fine, so what does it mean? Look closely at your switch statement. A switch statement contains case labels, which provide […]

Using errno

Lots of functions in the C standard library will set errno to an error code if something goes wrong, so using errno in your programming can help you pinpoint where problems are occurring and what they might be. errno remains set at the last error code, so bear in mind that: a) if two subsequent […]

Bitwise RGBA Values

Let’s take a look at bit shifting in practice. Say we have a variable called colour, that contains an RGBA value. If you have never had any experience with graphics, all you need to know is that the colours you see on your screen may be represented as a combination of four different variables – […]