What does the word "literal" mean?

prodev42 picture prodev42 · Jan 27, 2009 · Viewed 44.3k times · Source

What does the word "literal" mean when used in context such as literal strings and literal values?

What is the difference between a literal value and a value?

Answer

Iraimbilanja picture Iraimbilanja · Jan 27, 2009

A literal is "any notation for representing a value within source code" (wikipedia)

(Contrast this with identifiers, which refer to a value in memory.)

Examples:

  • "hey" (a string)
  • false (a boolean)
  • 3.14 (a real number)
  • [1,2,3] (a list of numbers)
  • (x) => x*x (a function)
  • /^1?$|^(11+?)\1+$/ (a regexp)

Some things that are not literals:

  • std::cout (an identifier)
  • foo = 0; (a statement)
  • 1+2 (an expression)