Character constant:
A single character enclosed in
two closing single quotes/ single inverted commas (’ ’) is said to be character constant. Both
the inverted commas should point to the left.
For example, Û¥AÛ¥ is a valid character constant whereas ‛AÛ¥ is not. Note that the character constant Û¥ 5Û¥
is not the same as the number 5.
Valid Character Constants: Û¥rÛ¥
Û¥=Û¥
Û¥AÛ¥
Invalid: Û¥543Û¥
- Length should be 1
"V" - Enclosed in single
quotes
Rules for Constructing Single Character constants
1. A single character
constant or character constant is a single alphabet, a single digit
or a single
special symbol enclosed within single inverted commas. Both the
inverted commas
should point to the left.
2. The maximum length of a
single character constant can be one character.
3. Each character constant has
an integer value known as ASCII value.
For example-
printf(“%d”,’a’);
So it prints 97 because lower case ’a’ ASCII value is 97
String Constant
- A set of characters enclosed in
two closing double quotes is said to be string constant.
- A characters may be letters,
numbers, special character and blank space.
Example: "Vivekanad College"
"Hello!"
"2022"
"?....!"
"4-2"
"W"
0 Comments