Character constant in c program
A character constant is a single character, enclosed in single quotation marks.
e.g., ‘A’ ‘B’ ‘1’
A character constant is a single character, enclosed in single quotation marks.
e.g., ‘A’ ‘B’ ‘1’
#include<stdio.h>
#include<conio.h>
int main()
{
const char a = ‘X’;
clrscr();
printf(“Value of a = %c , a ”);
getch();
return 0;
}
Value of a = X
A character constant is a single character, enclosed in single quotation marks.
e.g., ‘A’ ‘B’ ‘1’
Characters are stored internally in computer as coded set of binary digits, which have positive decimal integer equivalents. The value of a character constant is the numeric value of the character in the machine’s character set. This means that the value of a character constants can vary from one machine to the next, depending on the character set being used on the particular machine. For example, on ASCII machine the value of ‘A’ is 65 and on EBCDIC machine it is 193.
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.