Beginners Guide to C++ Programming - Part 2

Easy to Follow Instructions

Before we get into the code we are going to go over a basic tool, a variable. If you do not know what a variable is then you’re in big trouble! Just kidding, I will explain what a variable is. If you remember math class in school then you should have an idea of what a variable is.
 Possibly the most used and popular variable ever used in math is the letter X. Ah, brings back memories doesn’t it? Look at the below equation:


x = 2 + 2


The answer to this equation should be apparent but it is still represented by the letter x. It is basically a ‘holding’ spot for when you want to write an equation down and your really do not know the answer to. Say for instance we change the above equation to the following:


456 / 5 * 6 + 99 *46 / .09 = ?


Now the answer to that equation isn’t very evident. Mixing grammar and math is bad practice and they do not go well together. Instead of using the ? symbol you would use the letter X. Regardless if you know the answer to the above question or not, you do know that the answer IS x, whatever x may be. Variables in math work similar to variables in almost any programming language. The best part of using variables in a programming language is that they can be made up of whatever you can think up. However there are a few rules you have to follow.




  1. Has to start with a letter

  2. Can not use reserved keywords (we will get into this later)

  3. Can not use mathematical or foreign characters (nothing like ¿ ( á + -↓+? )

  4. Can not be the same as a previous variable.



Related information
  • Variables add an immense amount of power to the C++ programming language
  • Keywords are identified by bold words.
  • Part 3 Coming Soon!