What is a Variable and How does it works?
What is a Variable and How does it works

What is a Variable and How does it works?

Whenever you start learning any programming language the most basic thing you will learn is a “Variable”.

Today we will learn what is a Variable and how does it work in any programming language.

For those who are new to programming language, Variable is not a new phenomena if you have studied basic mathematics then you could remember “Father Son Age Problems” in mathematics where you solved questions like

“The current age of father is 40 and Age of Son is 20….” In the similar question you had to assume the age of father or son as “x”.

So You use identifiers like x, y or z. Rather than writing “age after 20 years of father will be…” .
Age of Father after 20 years will be = x

Here you are assigning and storing the whole thing in an identifier as x.

Rather then typing “Age of Father after 20 years will be”

“Age of Father after 20 years will be…”

“Age of Father after 20 years will be…”

again and again in progressing equations you only type X.

In more simple words you are storing data in a box named x.

And that what Variable is.

Isn’t it simple?

Now,

Let’s understand it in a better way for programming.

A variable is a container (like a box) where you store values.

These values can be a character, string(word), number, numbers with decimals etc.

After storing values in a container (or Box) you give a name to it.

Naming variable is very important because in future you may create more boxes of data and if you haven’t named any of the box then it will be hard for you to identify which box contains which data.

All the programming languages have their own standards of giving names to variables.

The most important thing to consider while naming any variable is not use reserved name.

Reserved name are already hard coded for the specific purpose in a program, If you are going to use those reserved names then you may face error initially or your program may not run at all.

As of now you have learnt about what a variable is.

 

It’s a box where you store your data and name it for future references.

 

Let’s take it to the next level and understand how a variable works?

As I said before, it’s a box filled with data.

You all know very well that data is stored in a memory.

A computer memory is a set of boxes where your data is stored.

A computer has a memory and that variable is stored in your computer memory space (one box of your computer memory).

Computer Memory
Computer Memory

How much space does a variable occupy in memory depends on How much data it holds in it.

Whenever you want to use the data use the data again at any stage of programming, you don’t need to type the data again.

Rather just type the variable name (Box Name) and then the compiler will automatically open the box, read the data and calculate it.

The next question comes here is

what type of data you can store in any variable?

It depends on the data type you want to store. The most common data types are Numbers (Odd, Even, Prime, Without decimal, with decimal). You can store a string of characters (words), Lists, Dictionary.

Where I can see the use of variable practically in real life example?

Facebook Login
Facebook Login

Facebook Login. Everytime you login to facebook account you are using a dynamic variable.

At the time of registering on facebook you give your desired username (Email id) and memorable password.

Here you are assigning data to variable whose name are username and password.

Next time when you try to login to your facebook account.

You type your user name in one box and password in another box.

Both box accepts variable input from your end.

All the users have different username and passwords.Variable can be dynamic. This is another property of a variable.

Once the program accepts the data type then it looks into the database and if found the username password combination correct then you get successfully logged in.

This is how a variable works in a broad sense.

Camera in Excel

Akash Gurjar

Hi, I am Akash. I am Hobbyist Blogger and YouTube Creator. I like to explore and learn new things all the time. I own a website easyexplain.info and a YouTube Channel EasyExplain. Join Me.

Leave a Reply