No products in the cart.
Variable is a name that can be used to store the values or data. Here, A data type is associated with each variable. The data type of variable decides what value it can take. The data which is stored in the variables exist upto program’s execution, One’s program execution is completed then variables data also expires. The rules of naming a variables are same as that for naming identifiers.
Declaration of a variable:
we need to declare a variable before using in the program.Here, Declaration of a variable defines the name and datatype.The type and range of a value in the variable decides can store depends upon its datatype. The syntax of a variable declaration is shown below
int x; // Used to hold an integer.
float salary; //Used to hold a float value.
char grade; //Can hold/store a character in it.
Where the datatype may be int, char,float double etc,. Here, x is a variable of type int, salary is a
variable of type float, grade is a variable of type char.
we can also declare a more than one variable in a single declaration. For example
Here, x,y,z,temp are all variables of int type.
Rules to name a variable:
* Keywords are not allowed as a variable name.
* Variable name is not allowed start with a digit or numbers.
* Variable name can consist of alphabets, digits and special symbols like underscore _.
* Blank or spaces are not allowed in variable name.
Let’s write a program in which we will use some variables :
int main ()
/* variable definition: */
int x, y,z; // x,y,z are the int datatype variables
/* Initialization a valve in variable */
x = 5; // 5 value is stored into the x variable
y = 2; // 2 value is stored into the y variable
/* using addition operator */
z = x + y; // the sum of two variables x and y will stored into the z variable
/* display the result */
printf(“Sum is : %d \n”, z); // displaying the z variable
Sum is 7
Here, if we consider the program we are declaring the variables in the main program that to it has been declared before used. In the program, x,y,z are the int datatype variable and which the system will allocates the seperate memories for each variables. Later, in the program we are initialized the values to the variables I.e, x=5 and y=2. So here the value 5 is stored in the variable x memory location. Similarly, the value 2 is stored in the variable y memory location. So after performing the addition operation the sum value is stored in the z(z=5+2).
If a student is very ambitious about the career in embedded systems industry. They should have a very deep knowledge in the basics . There are lot of famous institutes for embedded systems training institutes in this field. We are the Professional training institute, in Bangalore are focusing on student’s deepest understanding in this field from its basics.