C plus plus constants or data type

C++ constants or data type

C++ Constants are data storage locations whose address is not accessible for the user although its value is stored somewhere in the computer’s memory. There value cannot be changed during the course of the program.
There are two types of constant normally literal constants and symbolic constants, which are classified, based on their representation.
1) Literal constants as a represented by their value. E.g: numbers like 1,2.3 or the characters like “z”, “y” are all Literal constants .
The classification of constants given bellow.
a) Integer
b) Floating
c) Character
d) String
e) Boolean

a)  C++ Integer:

Integers are numbers without fractional parts. Integers can be decimal, Octal or hexadecimal numbers. E.g.21 (decimal) ,023(Octal), 0*15(hexadecimal).
They can also be long are unsigned. To denote long, unsigned, suffixes such as P,Q,I can be used. E.g.155U, 1145u, 1L, 9LU, 91l (91 and L)

b)  C++ Floating literal :

Floating literal character the numbers with fractional parts. There are written in specific or common notation. Using, the specific notation, the exponent can be written as high that E or e fifth (E or e represents the power of 10) fifth. By default the Floating literal task than double precision (12 digit after decimal points).
Following the value with either F or f indicates a single precision literal constant for example In common decimal notation, that will 1256(double), 1145F (float) , 1788888(extended double)

c)  C++ Character literal:

An ASCII (American Standard code for information interchange) characters enclosed within the single quotes are called character literal. E. g. “a”, “9”,”^” are called character literals.
Additionally, a character literals can be preceded by L, as in L “b” this is spoken as a wide character literal. Wide character literal support language character sets, such as Chinese and Japanese, in which some of the character value cannot be represented within a single char.
Special character set (escape sequence)- when normal character of proceeded with a /(back slash), they work in different way. These are called escape sequence.
For example-
\n – New Line
\t -horizontal tab
\v-vertical tab 
\””- double quotes
They can be represented using literal constants.

d)  C++ String literal:

C++ String literal constant is composed of zero or one characters enclosed in double quotation marks. Non printable characters can be represented by their underlying escape sequence. A sting literal can extend across multiple lines. A backslash as the last character on a line indicates the string literal is continued on the next line. All string literals are terminated by null.
For example
”- null string
‘a’- string containing single character

e)  C++ Boolean literals:

Boolean literals constants have only two values i.e. Either true (non zero) of false(zero) value.

Leave a Reply

Your email address will not be published.