Javascript required

C++ Literals

Prev Next

It often referred to a constant.

C++ have several kinds of literals:
  • Interger literal or Interger constant : C++ allows three types of integer constant
    • Decimal (base 10) Integer Constant
    • Octal (base 8) Integer Constant
    • Hexadecimal (base 16) Integer Constant
  • Floating literal or Floating constant : Floating constant are numbers have fractional part.
  • Character literal or Character constant : when a single character is enclosed in single quotes, as in'u'

Escape sequence character represented with a backslash(\). There are some escape sequence:

Escape Sequence Nongraphic Character
\a Audible bell (alert)
\b Backspace
\f Formfeed
\n Newline or Linefeed
\r Carriage Return
\t Horrizontal tab
\v Vertical tab
\\ Backslash
\' Single quote
\" Double quote
\? Question mark
\On Octal number (On represents the number in octal)
\xHn Hexadecimal number
\0 Null
  • String literal or String constant : A String literal is a sequence of character surrounded by double quotes.

  • "arrow" size is 6 because string ends with a special character '\0' and it is treated a single character. Thus "arrow" will actually be represented as "abc\0" in the memory.

    "\ab" size is 3 because '\a' is escape sequence,thus one character.
Prev Next