Variables In C Programming Language:



In simple words we can say that c variable is nothing but the name given to the memory location in which we can store data for the manipulations. Every c variable has a specific data type which determines what type of data is to be stored in specific variable and what should be a range of it.

C variables value may be change during the program execution. Variables in c belongs to the any data type such as int,float,char,double etc.


Rules for declaration of variables


1.     Variable name
must begin with letter or underscore.


2.     Variable
name is case sensitive.


3.     We can use
any numbers and letters in variable name.


4.      Special symbols are not allowed escape underscore
(_) in variable name.


Defining variable:


Variable definition means the allocation of memory for the variable. Before using the variable it should be defined. So the system assigns the memory for that specific variable according to the data type of variable.



Syntax:



[



Data Type  var_name1,var_name2….var_nameN;




Data type- it refers to data type
of variable such as int,char,float etc.


var_name1,var_name2….var_nameN-
refers to an variable list. We can declare any number of variables.


Example:


int a,b;


char ch;


float n;

]


Assigning values to variables:



Assign values to the variables means storing data into the reserved memory location by the variables. Variables can be assigned at the time of definition and in the program also.


Assigning variable at the time of definition



[





int a=10;


char ch=’a’;

]


Assigning value in the program



[




#include<stdio.h>


int main()


{


int a,b,c;   
//defining variabe


a=10;          //assigning
value 10 to variable a


b=20;       //assigning
value 20 to variable b


c=a+b;        //assigning
addition of variable a and b to the c


printf(“Addition of a and b is:%d”,c);


return 0;


}

]


What is the lvalue and rvalue?



Generally we listen about rvalue and lvalue in programming, many of those can’t understand what is actual what is rvalue and lvalue.


Lvalue: lvalue
always refers to a memory location. It points to memory address. It may be on left hand side and right and side also. Variables are comes into this categories.


Rvalue: rvalue
always refers to numeric values. It always present on right hand side but not left hand side. Rvalues always assigns to variables. Values cant be assign to rvalues. 


[
A       =      10



Lvalue   rvalue

]

Conclusion:
Here we discussed about Variables in C , if you have any query regarding this please comment below.
                                                         

Post a Comment

Previous Post Next Post