Concept of variable
A variable is a storage where we can store the data value
and we can use the vale in our programming. A variable is a contender which is
contain some value, same type of variable can contain the same type of value
that means the integer type variable(int a) can contain the integer type value.
Here int a; means ‘a’ is a variable and the type of a is “int” (integer type)
and the value which will store in the ‘a’ variable is also integer type . Suppose
in a coding if we add two number’s 5 and 10 then we can get the clear and write
out put but if can use the variable and then store 5 in a variable and store 10
in another variable and then store the summation result in another variable
then also we get the same result but facility is to use the variable is that
the value 5 and 10 is store in a specific area which is depend on the
programmer.
A) Without using variable B) Using
variable
# include <stdio.h> #include
<stdio.h>
void main() void
main()
{ {
Printf(“Result
is : %d ”,5+10); int
a,b,c;
a
= 5;
} b = 10;
c = a+ b;
Printf(“Result is: %d ”,c); }
OUTPUT: OUTPUT:
Result is : 15 Result is: 15
Here the upper example of two programmes to show the result
of summation of 5 and 10 then but (A) is a programme where we can’t use any
variable so that if we want to access the 5 or 10 which is used in our programme
then we are not able to do that because the value is not stored anywhere so
that we can’t access the value, where as the other programme (B) is a programme
where we can use the variables, so that we can get the same result but in a
different way and very efficient way. The (B) programme where we can use the
variables where we store the value 5 in ‘a’ (a = 5) and store the value 10
store in ‘b’ ( b = 10) and store the value of summation in ‘c’( c = a + b ) here a,b,c are variable
and int a,b,c; means here we declare the variables(a,b,c) are
integer type that means a,b,c is a variable where we can store the integer type
value and here 5, 10, 15 all are integer type value. In the above programme we declare
that a = 5 , b = 10 that means here 5 as ‘a’ and 10 as ‘b’ so when we use a + b
then the internal process is 5 + 10 and store the value of summation in ‘c’. So
if the both the outputs of A and B programmes are same but the whole operation
are not because if we use the summation value of the A programme then we are
not able o do that as we don’t know that where the value 15 or 5 or 10 are
stored in ram where as in the second programme using variable, we can access
the all value 5 as ‘a’, 10 as ‘b’ , 15 as ‘c’, so the programme which is using
variable is more efficient and the quality of programme is better than the
other one.
Why we use the
variable in our programme:- variable means we can store the required
information to a particular name.
Access: - in a programme when we want to work with a data then we
need to store the important data to a specific storage because we use the data in our programme so if we
don’t know that where the data in being stored then how can we get the data.
Example:-
#include <stdio.h>
int main()
{
int
a=10;
printf(“value
is %d”,a);
a=a+5;
printf(“\nnew value is %d”,a);
}
Output:
Value is 10
New value is 15
So the upper programme, at fast we assign (a = 5) a value
and then we can reuse the value which is stored in the variable ‘a’ and easily
done the required job.
Storage: variable is a storage where we can store the data
or value, we can store the data of the variable type that means we can store
value or data if the data type and the variable type are same and the length of
the data is less or equal to the variable length.
Example:
int a; here int a means “int” is a data
type that can hold the integer type of data and ‘a’is a variable which type is
integer that means ‘a’ is a variable that can store only integer type data and
the length of the integer type data is 2 byte that means 16 bit the range of
the integer is -32768 to +32767 .
float a; here float means real type variable that can hold
the value of real type means exponent value. The range of the variable float is
4 byte or 32 bit 3.4E-38 to 3.4E + 38.
double a; the double data type is use 8 byte or
64 bit and giving a precision of 14 digits and the double and float data type
are same type but double can provide the
greater precision than float.
Full concept of variables:
#include
<stdio.h>
Int main()
{
int a;
int b =
5,c = 10;
float d
;
char e
= ‘X’,f;
printf(“Enter
the value of a”);
scanf(“%d”,&a);
printf(“\nAddition of b and c is
= %d”,b+c);
printf(“\nEnter the value of
float “);
scanf(“%d”,& d);
printf(“ Enter the character
value of f is “);
scanf(“%c”,&f);
printf(“The characters are
%c & %c”,e,f);
return 0;
}
OUTPUT:
Enter the value of a 20
Addition of b and c is = 15
Enter the value of float 2.5
Enter the character value of f is A
The character are X & A
DISCUSSION: The
upper program is showing that the use of some variable, at first line “ int a
” means declare a variable ‘a’ as integer that means the variable can hold only
integer type of data.
The second line “ int b = 5, c = 10;” means here the
technique is called initialization during declaration, that means b = 5 is a
process called initialization that store 5 in ‘b’ but in the line int b = 5, c
= 10; means “int b “ declaration of the variable of what type is this, this is
a process where initializing the variable during declaration. Declaration means
just declare that the name of the variable
and the type of the variable but when we initialize any variable then a space
is require in RAM for the specific variable and store the value. float ‘d’
means float is a real type and d is the
variable that means declare that ‘d’ is a floating type variable which hold the
real numbers like 2.5f,3.6f.(float numbers denote through ‘f’).and char e=’X’,f
; means ‘e’ is a character type variable which hold the value of ‘x’ is just
one byte it’s called initialization during declearation and char f means just
declere the variable ‘f’ is a character variable.
Type
|
Size(bits)
|
Control string
|
Range
|
Char or signed char
|
8
|
%c
|
-128 to 127
|
Unsigned char
|
8
|
%c
|
0 to 255
|
Int or signed int
|
16
|
%d
|
-32768 to 32767
|
Unsigned int
|
16
|
0 to 65535
|
|