Variables

Suppose we want to print the value of 1024*1024 twice.

The simplest form of our code would be something like this:

untitled

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:

untitled

 

Advertisements
Variables

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s