What are literals in C++?

C++ProgrammingObject Oriented Programming

A literal is any notation for representing a value within the source code. They just exist in your source code and do not have any reference a value in memory. Contrast this with identifiers, which refer to a value in memory.

There are several types of literals in C++. Some of the examples of literals are −

  • "Hello" (a string)
  • 3.141 (a float/double)
  • true (a boolean)
  • 3 (an integer)
  • 'c' (a character)

Things that are not literals −

  • bar = 0; (a statement)
  • 3*5-4 (an expression)
  • std::cin (an identifier)
raja
Published on 16-Feb-2018 11:46:14
Advertisements