Skip to main content

What is Variable?


In our School life , we have seen something like a + b = c where,
                                                                                 a = 8,
                                                                                 b = 2 , so c = ?

Well we can solve this mathematical problem , right ? But what if we want to solve the same problem throughout any Programming language , then something called "var" came to picture . So take a seat , and let's start ..

  In Programming language, if we want to adding two digits for example 3 + 5 and want to print it , we can print also .. But we have to store his two digits somewhere , right ? Let we store 3 into x , and 5 into y . So x = 3 , and y = 5 .But how machine will know or can recognize them ? For this reason variable is came .

   Variable is a factor or element which can store or vary any type of value , it maybe floating type or character type etc . So should we called it Variable or Variable , it will be Variable .
 
  Now in different Programming languages it comes into different way . 
For example : if we go through C language , we have to mention type of the value which is nothing but some predefined keywords , let's see an example below :  


In the above example , we have declared a variable called "a" , and this is integer type variable so we have written the keyword "int" which is present in C library . And then we have initialized it with value 5 .
 Also I have shown u some common datatypes in C .

   In case of JavaScript,we just have to put a keyword called "var" . But we don't have to put data type.Let's see with an example below :


   But in case of PHP , we don't have to mention datatype before declaring it , Cause PHP is so smart after all ..We just have to put "$" sign before variable name. Let's see with an example below:



 So there are many Programming languages and their are different way to declare a variable . I have just given example of C ,JavaScript and PHP .

  So Variable's value is not permanent , I mean we can modify anytime depending on situation .For example , $a = 5 ; so now "a" is holding value 5 but if we want to store 7 into "a" then it will replace with value 5 .But what if we want to initialize a value permanently according to Program requirement , in that case "Constant" is comes into picture  . Let's just see an example below : 


 Here "const" is a predefined keyword which indicates PI ( variable ) is a costant type of double type variable. Floating is nothing but a data type .
So I hope you understand today's topic .Practice more..

  Please follow my facebook page link below :
     https://www.facebook.com/Code-Religion-795982750772492
   
    Keep Learning  :)
    Thank You .

Comments

Post a Comment

Popular posts from this blog

What is Class and Object in Oops || definition of Classes & Objects

We can make a program in Procedure oriented like C . But when C++ comes and says about Object Oriented Programming Language ( Oops ) , then Class & Object comes into picture . If we want to make a program in object oriented,then we must have to know about Class & Object which is main attributes of Oops . If you don't know much about it, don't worry . Take a seat , and let's start .   Class is a blueprint of Object where Object is a real world entity . Now whoever reading this blog , consider that I am a Object , that's great .. Now let's see with an example below then will discuss rest   ..       So if I consider Human as a Class & myself as an Object , then its definite I must be some properties and behavior .. So here we can say skin color , age , eye color , height etc as properties of myself . I am 22 year's old so 22 year's is an property and I can talk so here talk() is an function ( behavior ) of myself . So there are s...