We have learnt about data types . Now we are going to see how we are going to store data using Programming Languages.
If you want to store things , You would need a container

That container name is variables. You have some things for kitchen . If You want to store them you will need a house. You have to buy or rent a house.
Here , we have to declare a variable to store data.variables a container to store data

How Can We Use Variables?

Two things is important when declaring variables
  • variable name
  • variable size
We all have a Name. Why? For identifying .
In Programming we are going to reserve some space in memory.we are going to use that space for storing data. For example,I have stored some data in that space. Now i want to see the data. But how i am going to say that to computer? In Memory , there will be plenty of spaces.Not only the thing you stored. We need to identify our data. That's the where the thing 'id' comes.An Unique id to every spaces. Yeah! computer memory is divided into blocks and bytes. Computer will identify it with number. You can use that number to identify. That number will be like this,
0x5423523A324F
It seems like we can identify our data with this. but we can't remember that. Here our another problem is
We can identify data with numbers, but can't remember
That's why we have to give a name to our space.That's called variable declaration.Just like naming a human. In Programming we have some restriction in naming the variable.
  • can use letters and numbers
  • can use underscore character(_)
  • shouldn't start with number
Here are some examples for variable Name
firstname_/
firstName_/
1stnameX
first_name_/
first-nameX
shouldn't use special characters other than underscore(_)
We are done with the naming.

Variable size

When we are reserving space in memory we have to specify how much space we want. That's our variable size. But in some languages you don't have to specify the memory space.That will automatically reserve a space.That's not our case here. Languages will give some pre fixed variable size. we have to use that for reserve a space. just need to specify that before variable name.
You can't choose your own size for variables
Those prefixed size names will vary for languages. Also you have to define variable format.Click Here for variable formatvariable size and variable format both are declared using same thing. For Example,
int answer;
It is variable declaration in c .
Here the word 'int' means integer (Number) and 4 Bytes of space.
It is variable declaration in c .