Variables: The Little Building Blocks of Programming
When I think of variables, I think of the long-term memory storage in the human brain. It contains basic information that we retain and access when needed. Data such as your name, age, weight and location are all different variables. The value of those variables can be changed, just like they do in real life as we age or even just move around. Imagine your current location as a variable with a value that can be constantly updated via GPS should you happen to walk around with a smart phone in your pocket with location services activated.
The four main data types that a variable can take are: float (numeric value with a decimal place such as 5.3), int (whole numeric values such as 5), bool (a true or false statement), and string (text values).
Fun fact: Every variable stores it’s value and data type in a small part of the computer’s memory, called a memory address.
In order to declare a variable, there are a few simple rules to follow. Every variable needs to start by stating it’s data type. It then needs a unique name. While this name can be whatever you want it to be, it’s best to have the reference make as much sense as possible for it’s purpose. You can then give it an assigned value. Not to be forgotten, is the semicolon which acts as a period to our sentence.