![]() |
| Constants in C Programming |
Constants: A constant can be used program that value cannot be changed at the time of execution of program that is called constant. It is also called literals. It may be integer, float and character data types constant. Constant in C are fixed value that is can't change value of the run time program.
Const Keyword: A constant keyword makes a variable read only and is handling by the compiler provided security and program scope.
How To Use Constant in C
| #include<stdio.h> #include<conio.h> void main(){ clrscr(); const int x=100; const float y=67.8; const char c='J'; const char n[20]="jiocoding"; printf("Value of x:%d\n",x); printf("Value of y:%f\n",y); printf("Value of c:%c\n",c); printf("Value of n:%s\n",n); getch(); } ============OUTPUT============ Value of x:100 Value of y:67.8 Value of c:J Value of n: jiocoding |
#define Preprocessing Constant: This is a Constant defines a symbolic constant. There is no need considerer any data type.
Example of Preprocessing Constant in C
| #include<stdio.h> #include<conio.h> void main(){ clrscr(); printf("Value of PI:%.2f",PI); getch(); } ============OUTPUT============ Value of PI:3.14 |
What is Integer Constant in C
Integer Constants: Integer Constant is a whole numbers positive, negative, or zero without decimal points. The range of integer constant is between -32768 To +32768. No comma or blank space are not allowed in integer constant.
Example of Integer Constant in C
| #include<stdio.h> #include<conio.h> void main(){ clrscr(); const int x=100; printf("Value of x:%d",x); getch(); } ============OUTPUT============ Value of x:100 |
Floating Constant in C with Example
Floating-Point Constants: Floating point number is a at least one digit. It is decimal point number. It is a positive or negative number. No comma or blank space are not allowed in floating number.
Example of Floating Constant in C
| #include<stdio.h> #include<conio.h> void main(){ clrscr(); const float x=78.8; printf("Value of x:%f",x); getch(); } ============OUTPUT============ Value of x:78.8 |
Character Constant in C Language
Character Constants: A single character, digit, or special symbol. The length of character constant is 1 character. Enclosed within single quotes( 'J', '9', '*'). Each character has an associated ASCII value.
Example of Character Constant in C
| #include<stdio.h> #include<conio.h> void main(){ clrscr(); const char c='J'; printf("Value of C:%c",c); getch(); } ============OUTPUT============ Value of C:J |
What is String Constant in C
String Constants: A sequence of characters including letters, digits, and special symbols enclosed in double quotes ("Jiocoding", "Jiocoding@").It is called by string constant.
Example of String Constant in C
| #include<stdio.h> #include<conio.h> void main(){ clrscr(); const char name[10]="Jiocoding"; printf("Value of Name:%s",name); getch(); } ============OUTPUT============ Value of Name: Jiocoding |
Constant Conclusion in C Language
Conclusion: A constant is a important part of C language. Constant value is not changeable. I hove your doubt constant related are clear. If any query you can comment or contact me.

0 Comments