Fundamental concepts of programming Part #1 Variables

Although the book, C++ Better Explained is dedicated to learning C++, if you can master the 4 major fundamental concepts of programming, you will have no problem in understanding any programming language or making the transition to learn another object orientated programming language such as Java or C# as they are very similar.

4 Major Fundamental concepts of programming:

  1. Variables
  2. Control Structures
  3. Data Structures
  4. Syntax

What is a variable?
In simple English, a variable stores data in which they are stored on the random access memory on your computer. It will contain a known or unknown value of information. Two real life examples of variables being applied in programming are controlling your character in a video game with or paying your bills via online banking.

The variables used to control your character in a video game would be the input from either a game controller or the keyboard. The variables applied in online banking would be the amount you are entering in from your bank account, to pay your bills.

Types of variables

Digging deeper into the concept of variables, in programming there are four major types of variables we can declare. These include

  • Integers
  • Doubles
  • Strings
  • Boolean

Now you might be asking, how do I know what variable I should declare? Great question. You need to understand the different types of variables in order to properly declare one, otherwise your code will not work properly.

Integers – If you are working with whole numbers like 18, 120, 39 and not decimals like 50.6 or 29.864, use integers. An example would be storing your age as a variable as that would perfectly store a whole number and you are not required to handle decimals.

Doubles – Used for calculations with decimals, handy for Mathematical calculations such as creating a program to calculate Pythagoras theorem. Double is also useful for storing money values as money values deal with decimals.

Strings – If you need to store a line of text instead of numbers. You cannot use the string variable to store numbers. An example of using a string would be to store a book title name or street names as variables can be reused again and again in different segments of code.

Boolean – Known as bool in programming, which means it’s either a true or false statement. Boolean cannot store numbers or lines of text. A real life example would be if your playable character was dead in a video game, a Boolean variable that was currently on false will trigger to true and end the game.

Summed up

A variable is something that stores data which are stored in the random access memory. Variables are one of the most important things in programming because they are applied everywhere. There are four major variable types which are Integers, Doubles, Strings and Boolean. To find out what type of variable to use, you must first understand how each type works and assign the correct type to the application you are creating.

Share this post