Constants refer to the fixed values that can not be changed throughout the entire program.
Constants can be of any data type and is divided into Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.
Integer literals
An integer literal can have suffix like U or L, for unsigned and long, respectively. The suffix can be uppercase or lowercase and can be in any order.
212 // Legal
215u // Legal
0xFeeL // Legal
078 // Illegal: 8 is not an octal digit
032UU // Illegal: cannot repeat a suffix
Following are other examples of various types of Integer literals:
85 // decimal
0213 // octal
0x4b // hexadecimal
30 // int
30u // unsigned int
30l // long
30ul // unsigned long
Floating-point literals
A floating-point literal can have integer,decimal,fractional ,exponent part. You can represent floating point literals either in decimal form or exponential form.
3.14159 // Legal
314159E-5L // Legal
510E // Illegal: incomplete exponent
210f // Illegal: no decimal or exponent
.e55 // Illegal: missing integer or fraction
Character Literals
Character literals are enclosed in the single quotes. If the literal begins with L (uppercase only), it is called as a wide character literal .
| Escape sequence |
Meaning |
| \\ |
\ character |
| \' |
' character |
| \" |
" character |
| \? |
? character |
| \a |
Alert or bell |
| \b |
Backspace |
| \f |
Form feed |
| \n |
Newline |
| \r |
Carriage return |
| \t |
Horizontal tab |
| \v |
Vertical tab |
| \ooo |
Octal number of one to three digits |
| \xhh . . . |
Hexadecimal number of one or more digits |
0 Comment(s)