Thursday, January 21, 2016

Character constants

Character constants hold a single character enclosed in single apostrophes. Characters are short integers. So, it can hold an integer value as well (maximum value character constants can hold is 127 and 255 for unsigned character constants). Also, different characters have associated integer values (like 'A' is 65, 'a' is 97 etc.). These values are standard and known as ASCII (American Standard Code for Information Interchange).
There are some characters which have special use in C language compared to other characters. They are preceeded by a backslash(\) (like \n, \b). These characters are called escape sequences. Below, you can find examples of escape sequences available in C.
CharactersEscape sequence
bell\a
backspace\b
horizontal tab\t
vertical tab\v
newline\n
form feed\f
carriage return\r
quotation mark\"
apostrophe\'
question mark\?
backslash\\
null\0
For example, using '\n' in printf statement will feed a line in the output. Character constants can hold escape sequences too. Examples of few of the character constants are given below.

'a'
'b'
1
2
'\n' 

Enumeration Constants

Enumeration constants represents the individual values of an enumeration set. They are actually integer literals internally. In the following enum 'Boolean', we've two enumeration constants 'TRUE' and 'FALSE'. They internally has integer constant values 1 and 0 respectively.
  1. enum Boolean
  2. {
  3. FALSE = 0,
  4. TRUE = 1
  5. }

No comments: