How are character constants represented in C language programs?
Characters constants in the C language can be represented in two ways.
- Single characters enclosed in single quotation marks, such as ‘a’, ‘1’, ‘@’, etc. This notation can only represent one character.
- Special characters can be represented using escape characters, for example, ‘\n’ represents a newline, ‘\t’ represents a tab, ‘\b’ represents a backspace, ‘\r’ represents a carriage return, and so on. This method allows for the representation of certain special characters.
Here are some common ways to represent character constants:
- Single character constants: ‘a’, ‘1’, ‘@’
- Escape character constants such as ‘\n’ (newline), ‘\t’ (tab), ‘\b’ (backspace), ‘\r’ (carriage return), etc.
- Special character constants such as ‘\0’ (representing the end of a string), ‘\” (representing a single quote character), ‘”‘ (representing a double quote character), and ‘\’ (representing a backslash character) are used.
It is important to note that character constants can only contain one character, while string constants can contain multiple characters. Character constants are stored in memory in the form of integers, for example, the character ‘a’ corresponds to an ASCII code of 97.