Pointers are variables that point to a pointee. Like so: Behind that deceptively simple definition lurk some pretty hairy pitfalls and subtleties but it’s still the best place to start learning. In computing, when we’re talking about locations to point to and/or from, we’re really talking about memory addresses. So, given that we’re talking aboutRead more »

The top-level answer to this is that pointers often lead to smaller and faster code. As answers go, that’s not very enlightening though so here are a few concrete examples. To allow functions to change data owned by their caller. This allows you to avoid using global variables for changing data within functions. It alsoRead more »

In addition to the familiar pointers to standard types like ints, floats, arrays and structs, we can also have pointers to pointers: int i = 1; int *ip = &i; int **pp = &ip;

There’s just one little wrinkle you need to know about structs when it comes to pointers. If you have a pointer to a struct and you want to get access to one of its fields then there’s a shorthand: ptrToStruct->fieldName is the same as *(ptrToStruct).fieldName

Arrays are contiguous blocks of memory holding multiple objects of the same type. These can be quite large and passing them into functions in the conventional, by value sense, can be quite inefficient both in terms of memory and processor cycles. Fortunately, pointers come to our rescue here by allowing us to pass a pointerRead more »

C is a statically typed language, meaning that we explicitly tell the compiler what type our objects are. For example, in Python, which is dynamically rather than statically typed, we’d write value = 12 whereas in C we’d write int value = 12. What about pointers then? Given that we write int value1 and floatRead more »

The null pointer in C is a bit of an odd beast. It’s a pointer that doesn’t point to anything. Specifically, it doesn’t point to an object in memory and it doesn’t point to a function either. Now, you might think that’s what you get when you first declare a pointer i.e. the statement intRead more »

This is just a stub for now but in order to avoid your inevitable disappointment have a lovely link.

Pointers, as you would expect given the not insignificant clue in the name, point to something. Although that’s not necessarily as obviously true as you might think. They point to the memory word at the address specified by the contents of the pointer. This is often referred to as the pointee. That’s all fine andRead more »

This is just a stub for now but in order to avoid your inevitable disappointment have a lovely link. From a top level perspective you can think of each bit of computer memory as having the following functionality. It must retain its state (either zero or one) at least semi-permanently. RAM will often lose itsRead more »

Next Page »