You are on page 1of 3

Variables In 'C' | Programmerdouts

programmerdouts.blogspot.com/2019/06/blog-post_5.html

VARIABLES
A variable is identifier which stores the data value
it is a symbolic name assigned to the memory location where data is stored
A variable can have only single data item at any given item duration the program
execution
A variable can take different values at different times during execution
assignment of value to a variable is done by the (=) assignment operator

*Note:- (=) operator is not an 'equal operator' that is an assignment operator, equal
operator we will going to see it on further modules

Declaration of variable
In,'C' when we have to use an variable ,first we have to declare it.

Let's understand by Example of declaring a variables

#include<stdio.h> //header file

void main()
{
/*declaration of variables*/
int v1; // integer type of variable

float v2; // float type of variable

char v3; // character type of variable


}

Initializing of variables

1/3
#include<stdio.h> //header file

void main()
{
/*declaration of variables*/
int v1 = 10; // integer type of variable

float v2 = 10.12; // float type of variable

char v3 = A; // character type of variable


}

Lets see the output by printing the values

#include<stdio.h> //header file

void main()
{
/*decleration of variables*/
int v1 = 10; // integer type of variable

float v2 = 10.12; // float type of variable

char v3 = A; // character type of variable


/* printing the values*/
printf("integer Type variable is %d\n",v1);
printf("float Type variable is %f\n",v2);

printf("character Type variable is %c\n",v3);

Output:
integer variable is 10
float Type variable is 10.12
character Type variable is A
Note:- %d, %c, %f are format specifiers

below are the different specifiers

Specifier Description

%d store variable is of int type

2/3
%f stored variable is of float type

%c stored variable is of character type

%s stored variable has string

These specifiers are mostly used programming in 'C'.


remaining one's we will see when it is required

3/3

You might also like