Variable :
it is memory location where we store some data.
during the program execution value of variable could be change.
re-assignment is possible.
Variable has name, memory address and value.
Variable Declaration
_______________________
Syntax:
datatype variablename;
Ex:
int x;
Here x is int type of variable.
float y;
char z;
Ex:
int x;
int y;
int z;
or
int x,y,z;
Variable Assignment : providing some data to variable.
____________________
syntax:
variablename = value;
Ex:
int x,y,z;
x=23;
y=34;
z=43;
char c;
c='A';
float k;
k=4.5;
Variable initialization
_________________________
Syntax:
datatype variablename = value;
Ex:
int x=102;
char c='H';
float k=6.7;
format string
_______________
int - %d
float - %f
char - %c
Ques: how to print variable values.
printf() syntax---->
printf("format string", variablename);
#include<stdio.h>
int main()
{
int x;
float y;
char ch;
x=-10;
y=4.5;
ch='K';
printf("%d\n",x);
printf("%f\n",y);
printf("%c\n",ch);
return 0;
}
Ex:
#include<stdio.h>
int main()
{
int x;
float y;
char ch;
x=-10;
y=4.5;
ch='K';
printf("%d\n",x);
printf("%.1f\n",y);
printf("%c\n",ch);
return 0;
}
Ex:
#include<stdio.h>
int main()
{
int x=4;
float y=7.8;
char ch='P';
printf("%d\n",x);
printf("%.1f\n",y);
printf("%c\n",ch);
return 0;
}
Ex:
#include<stdio.h>
int main()
{
int x=4;
float y=7.8;
char ch='P';
printf("x=%d\n",x);
printf("y=%.1f\n",y);
printf("ch=%c\n",ch);
return 0;
}
ex:
#include<stdio.h>
int main()
{
int x=4;
float y=7.8;
char ch='P';
printf("The value of x is %d \n",x);
printf("The value of y is %.1f\n",y);
printf("The value of ch is %c\n",ch);
return 0;
}