What is Constant?
Values which are stored by the variable is called "constant". Constant is a fixed value which can't be changed during the program execution. Without constant a program can't be succeeded.
Ex:- int a=10;
In the above example "a" is called variable and "10" is called constant that means, integer datatype can hold one integer type of data in a variable.
Example of different constant:
Sl No | Name of the Constant | Example |
01. | Integer constant | 120,5,45,69 |
02. | Float / real constant | 125.36,58.98,63.96,25.00 |
03. | Character Constant | ‘a’,’b’,’c’, |
04. | String constant | “Ram”,”Krishna”,”Laxmi” |
05. | Octal constant | 21,42,32,26 |
Example on Integer Constant
#include<stdio.h>
#include<conio.h>
main( )
{
int a=10,b=20;
c=a+b;
printf("%d is the addition", c);
return 0;
}
Example on Float/real Constant
#include<stdio.h>
#include<conio.h>
main( )
{
int c=75,java=78,html=68,sm=0;
float per=0;
sm=c+java+html;
per=sm/3;
printf("%d is the secured mark", sm);
printf("%f is the percentage of mark", per);
return 0;
}
No comments:
Post a Comment