What Are Variables?

Variables at the core are just containers of data. Rather than being very verbose and always having to justify the data and its value e.g. I have a quantity of 3 of type apples. You can just say, the variable apples = 3.

This makes keeping track of things a lot easier. Now depending on the language, there are different kinds of variables, but as we are going to be using Pseudo Code we will generalize the types.

TypeDescription
stringThis is anything from a single letter to a whole sentence. Strings can be anything as long as they are enclosed with quotes, either single or double.
numberThis is any digit, this can be 1 or 200 or even 876543. As long as there are no decimal places.
floatFloat is similar to number, except that it has a decimal, e.g. 7.4 or 8.55
doubleDouble is fimilar to float, but more accurate. It will track more digits after the the comma/point than a float.
So if accuracy is a requirement, then double will be used. Otherwise a float is fine if you need to only be within lets say 4 decimal places.
Different types of variables

While this certainly is not ALL the variables out there. This will take you 90% of the way.

With the examples of the Pseudo Code I will put the variable type before the name followed by the value. e.g.

string VariableName = "Hello World!"

There we have created a variable using our Pseudo Code!

Beyond The Basics

Now that the basic variables have been described, we can move to the slightly more advanced ways of storing data.

The most important one will be the “Array” this is used in almost all code at some point. An array is a set of data stored in 1 variable.

To explain this better, let me show you an example.

array Numbers = [100, 22, 35, 47, 125]

When working with arrays, the majority of the languages will used brackets to notate an array. This now means that when we refer to the variable Numbers it refers to all 5 numbers. This on its own is not entirely useful, the real magic happens when you start using an “index”. This is the position of a value, inside an array. e.g. Numbers[0] would be the number 100 (indexes start from 0).

So to show all the indexes:

array Numbers = [100, 22, 35, 47, 125]

Numbers at index [0] equals 100
Numbers at index [1] equals 22
Numbers at index [2] equals 35
Numbers at index [3] equals 47
Numbers at index [4] equals 125

Congratulations! You have leveled up in programming!


Next – Demystifying Programming – 3 Arithmetic

Previous – Demystifying Programming – 1 Programming

Leave a Reply

Your email address will not be published. Required fields are marked *