Tuesday, March 10, 2015

PROGRAMMING: "VARIABLE EXPLAINED !"

how variable stores data in a programming languge



Programming deals mostly with numeral and strings (words).. I'll like to put this section as easy and simple as possible and yeah! , it's applicable to all programming language but I'll be using Java as an example.


Must Read: What I Love About My Phone :)



Definition of A Variable

Any declaration in any programming language is always stored in a variable. And what is a variable? A variable serves as a warehouse where you can store strings (also known as words or sentences) and numbers. 


So any declaration in a program has to be stored immediately into a variable so at a later time, you can call up on it and use. Let me use a simple example.

A farmer harvested tubers of yam from his farm. After harvesting, where does he put those yam? A warehouse.








 



data stored inside variable is like yam to a warehouse





Because he can't just drop the yam on a floor unless he wants it stolen. So after storing the Yam, and later wants to eat boiled yam or pounded yam. He checks inside the warehouse, retrieves the yam and use it for the purpose of what he wants to use it for which is to eat!... same applies to variable(warehouse) and strings/numbers as Yam and you the programmer as the farmer.. Easy ei?‎ 


An Example On How To Store A Variable

First, you have to be real. Ask yourself these questions. What do I want to store and essence of what am storing at a latter day or time.


Alright, I want do a simple arithmetic (summing up/addition) with my stored variable. 


21 + 7 which is 28


I need to store the numbers in a variable before summing up. So I decide to name my warehouse (variable) number1 and number2 respectively. In order to declare them, 


int number1 = 21
int number2 = 7 






int over there is "data type" which means integer (21 and 7 are both integers).
Therefore in this case, my yam i.e the numbers are stored into my declared warehouse which are "number1" and "number2" respectively. Easy !


Now to add up, declare a new variable which I will call 'number' and sum up the earlier declared ones from there.


int number = number1 + number2


and the final answer will give us 28.


This explanation is applicable to all programming language. this is just the concept behind it



 

And share ,like or tweet this if it's helpful to you. thanks 

No comments:

Post a Comment

we love to see your comment