Category Archives: Development
In the previous post we learnt what pointers are, their properties, and how to use them. However, most likely this didn’t help understand why pointers are so useful or why we even need them at all. Today we’re going to take care of that.
Pointers are most valuable when combined with other functionalities of the C language. Let’s start by taking a look at how they work with arrays.Read more ›
Pointers are a special type of data in the C programming language (and also C-like languages). In short, a pointer is just a variable that contains the memory address of some data in the computer. It’s a simple concept, but pointers are always a source of confusion when we’re learning the language. However, once understood they become a powerful tool that provide lots and lots of flexibility.
Today we’re starting a short series explaining what pointers are and how they can make our programs much more interesting. As always, don’t hesitate to ask in the comments below when anything isn’t clear.
The address operator (&) and the indirection operator (*)
Computers store all program data and variables in an area known as memory. In MSX computers memory is organized in 65,536 cells(*), each containing a number between 0 and 255 (known as a byte).
Each memory cell is identified by a number between 0 and 65,535 (0x0000 – 0xFFFF in hexadecimal). We call this the memory address.
It’s easy to visualize this concept if we think of the computer memory as an spreadsheet with 65,536 rows, such as this one:Read more ›
We’ve already seen how to use local variables inside a function declaration. However, there are times when we want to be able to share the same variable between several functions. In this situation local variables aren’t the best solution.
There are other cases when we want to use a local variable, but we need the variable to retain its value between calls to the function.
In this chapter we’re going to see how to declare and use variables to support these two situations.
The storage class of a variable
All variables in C have a property called storage class. The storage class defines the lifecycle of a variable. This means that depending on this property, a variable can either be created and destroyed several times during the execution of a program (whenever we call the function or block that defines the variable), or created once and exist until the program finishes.
Variables in MSX-C can belong to one of the two storage classes below:Read more ›