printf() function.
#include <stdio.h>
int main()
{
int marks = 100;
float percentage = 99.50;
printf("Integer Constant = %d\n", marks);
printf("Floating Constant = %.2f", percentage);
return 0;
}
Integer Constant = 100
Floating Constant = 99.50
A constant is a fixed value that does not change during the execution of a program. Constants can be numeric, character, or string values. They are one of the fundamental types of tokens in C programming.
In this program, the values 100 and 99.50 are constants because their values remain fixed throughout the execution of the program.
| Constant | Type | Description |
|---|---|---|
| 100 | Integer Constant | A whole number value without a decimal point. |
| 99.50 | Floating-Point Constant | A numeric value containing a decimal point. |
The statement int marks = 100; assigns an integer constant to the variable marks. Similarly, the statement float percentage = 99.50; assigns a floating-point constant to the variable percentage. Constants provide fixed values that can be used in calculations, assignments, and output statements.
Common types of constants in C include integer constants, floating-point constants, character constants, and string constants.
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.