Constants in C
0 344
In C language, constants are like values that stay unchanged while the program is running.
They are used to represent Fixed Values such as Numbers or Characters.
Constants in programming come in diverse forms, including Integer Constants (whole numbers), Character Constants (single characters), Floating-point Constants (real numbers with fractions), and Symbolic Constants (named values representing fixed quantities).
Constants in C are containers that hold values that remain fixed throughout the program's execution.
They are like containers that keep things steady.
Constants prevent errors and improve code clarity.
For Example, you could have a box labeled "number" with the value 10 inside, and that value stays the same throughout the program.
These constants can come in various types, such as integers, decimals, or individual characters.
C Program for Constants in C Language
#include<stdio.h>Output:
int main()
{
const int value=10;
printf("Integer constant : %d\n", value);
const float pi=3.14;
printf("float constant :%f\n", pi);
const char letter ='R';
printf("char constant: %c\n", letter);
#define MAZ_SIZE 1000
printf("symbolic constant: %d\n", MAZ_SIZE);
return 0;
}
Integer constant: 10value, pi, and letter are constant types of integer, float, and character. Once defined their value can't be changed. MAZ_SIZE is a symbolic constant defined using #define.
float constant: 3.14000
char constant: R
symbolic constant: 1000
Constants are very important in C programs because they let us represent values that never change.
This makes our code easier to read and allows us to update or change our code more easily later on.
Making code easier to read and changing it more easily are also benefits of constants in C programming.
Share:
Comments
Waiting for your comments