Suppose we want to print the value of 1024*1024 twice.
The simplest form of our code would be something like this:
The problem of this code is we have to calculate the value of 1024*1024 two times. Instead of multiplying two times, we can use a temporary memory to store the calculated value. So, when we require the value of 1024*1024 again, we use that temporary memory instead of multiplying those values again. We named that temporary memory as a Variable.
Variables allow us to capture & reuse the result of calculation.
When you declare a variable, you’ll need to give a type of that variable first. Type of a variable identifies what it can hold. For example: int type can hold a number, string type can hold a name of a person
After you declare the type, you need to specify the name of the variable. This name can be use anywhere in your program where you want to use the value it holds.
Here is an example: