Home »
C programming language
Character Constant in C language
C language character constants: In this tutorial, we are going to learn about the character constants with their declarations, printing in C programming language.
Submitted by IncludeHelp, on September 08, 2018
What is a Character Constant?
Any character (a single character) that is enclosed within the single quotes (like, 'A') is called character constants in C programming language.
Character constants contain:
- Any uppercase alphabet
- Any lowercase alphabet
- A space
- A digit
- Any special character
Character constant Declaration in C
A character constant is declared by using const keyword.
Syntax
const char constant_name = 'value';
Example of a character constant in C
#include <stdio.h>
int main(void)
{
const char1 = 'A'; //uppercase alphabet
const char2 = 'X'; //uppercase alphabet
const char3 = 'a'; //lowercase alphabet
const char4 = 'x'; //lowercase alphabet
const char5 = '5'; //a digit
const char6 = '#'; //a special character
const char7 = ' '; //a space
//print values
printf("char1 = %c\n", char1);
printf("char2 = %c\n", char2);
printf("char3 = %c\n", char3);
printf("char4 = %c\n", char4);
printf("char5 = %c\n", char5);
printf("char6 = %c\n", char5);
printf("char7 = %c\n", char7);
return 0;
}
Output
char1 = A
char2 = X
char3 = a
char4 = x
char5 = 5
char6 = 5
char7 =
C Language Tutorial »