In a passage of text, individual words and punctuation marks are called tokens or lexical units. Similarly, the smallest individual unit in a c program is known as a token or a lexical unit. C tokens can be classified as follows:
- Special Symbols
C keywords are the words that convey a special meaning to the c compiler. The keywords cannot be used as variable names because by doing so, we are trying to assign a new meaning to the keyword which is not allowed.
The list of C keywords is given below:
Identifiers are used as the general terminology for the names of variables, functions and arrays. These are user defined names consisting of arbitrarily long sequence of letters and digits with either a letter or the underscore(_) as a first character.
There are certain rules that should be followed while naming c identifiers:
- They must begin with a letter or underscore(_).
- They must consist of only letters, digits, or underscore. No other special character is allowed.
- It should not be a keyword.
- It must not contain white space.
- It should be up to 31 characters long as only first 31 characters are significant.
Some examples of c identifiers:
|Temp.var||Invalid as it contains special character other than the underscore|
|void||Invalid as it is a keyword|
C constants refers to the data items that do not change their value during the program execution. Several types of C constants that are allowed in C are:
1. Integer Constants
Integer constants are whole numbers without any fractional part. It must have at least one digit and may contain either + or – sign. A number with no sign is assumed to be positive.
There are three types of integer constants:
1.1. Decimal Integer Constants
Integer constants consisting of a set of digits, 0 through 9, preceded by an optional – or + sign.
Example of valid decimal integer constants
341, -341, 0, 8972
1.2. Octal Integer Constants
Integer constants consisting of sequence of digits from the set 0 through 7 starting with 0 is said to be octal integer constants.
Example of valid octal integer constants
010, 0424, 0, 0540
1.3. Hexadecimal Integer Constants
Hexadecimal integer constants are integer constants having sequence of digits preceded by 0x or 0X. They may also include alphabets from A to F representing numbers 10 to 15.
Example of valid hexadecimal integer constants
0xD, 0X8d, 0X, 0xbD
It should be noted that, octal and hexadecimal integer constants are rarely used in programming.
2. Real Constants
The numbers having fractional parts are called real or floating point constants. These may be represented in one of the two forms called fractional form or the exponent form and may also have either + or – sign preceding it.
Example of valid real constants in fractional form or decimal notation
0.05, -0.905, 562.05, 0.015
Representing a real constant in exponent form
The general format in which a real number may be represented in exponential or scientific form is
mantissa e exponent
The mantissa must be either an integer or a real number expressed in decimal notation.
The letter e separating the mantissa and the exponent can also be written in uppercase i.e. E
And, the exponent must be an integer.
Examples of valid real constants in exponent form are:
252E85, 0.15E-10, -3e+8
3. Character Constants
A character constant contains one single character enclosed within single quotes.
Examples of valid character constants
‘a’ , ‘Z’, ‘5’
It should be noted that character constants have numerical values known as ASCII values, for example, the value of ‘A’ is 65 which is its ASCII value.
Escape Characters/ Escape Sequences
C allows us to have certain non graphic characters in character constants. Non graphic characters are those characters that cannot be typed directly from keyboard, for example, tabs, carriage return, etc.
These non graphic characters can be represented by using escape sequences represented by a backslash() followed by one or more characters.
NOTE: An escape sequence consumes only one byte of space as it represents a single character.
|“||Double quotation mark|
|‘||Single quotation mark|