Integer constants are of four types. Along with these four, there are other two constants called "Backslash Character and Wide Character Constant".
It takes values from "0 to 9" and sign is optional.
- Octal Integer Constant: It takes values form "0 to 7" and the sign that precedes the value is 0. For example: 0123.
- Hexadecimal Integer Constant: It takes values from "0 to 15" and the sign that precedes the value is 0x. For example: 0x123
Floating Point Integer Constant
It represents a real integer value i.e it takes "Fractional, Decimal and Integer Values".
- Float: They are defined using "float" keyword and takes two bytes of memory.
- Double: This is used when precision provided by the float is not sufficient and takes four bytes of memory.
- Long Double: This is used to extend further more compared to double and takes eight bytes of memory.
A character constant can be an "Alphabet, a Digit or a Single Special Symbol".
- This can hold a single character at a time and value should be enclosed in single quotes''.For example: char c='A'.
- Format specifier for character constant is %c.
String constant is same as character constant, and can be enclosed in double quotes
" ". There is no special datatype for string.
For example, char area= " A"; Here "char" is only used as datatype.
Backlash Constant is another constant that is used in C-language.
Backslash character constants
This should be started with backslash.
Symbol |
Backslash Symbol |
\b |
Backspace |
\v |
Vertical tab |
\" |
Double Quote |
\r |
Carriage Return |
\t |
Horizontal Tab |
\f |
Form feed |
\\ |
Backslash |
\? |
Question Mark |
\a |
Alert or Bell |
\' |
Single Quote |
\n |
New line |
Wide Characters in C++ are declared using Wide Character Constants. The values up to 16 bits are allowed here. To make a constant wide character place"
L "before it.
Syntax:
wchar_t character_name=L'character';
For example,
wchar_t c=L'A';