Literals in C Programming

Posted by Tushar Bedekar
The term literal constant or literal refers to a value that occurs in a program and cannot be changed. The C language uses the term constant in place of the noun literal. The adjective literal adds to the concept of a constant the notion that we can speak of it only in terms of its value. A literal constant is nonaddressable, which means that its value is stored somewhere in memory, but we have no means of accessing that address.

Every literal has a value and a data type. The value of any literal does not change while the program runs and must be in the range of representable values for its type. The following are the available types of literals:


Types:-


  • Boolean
  • Integer
  • Character
  • Floating-point
  • String
  • C Compound literal
  • Vector literal
According to Wikipedia  a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers,floating-point numbers, and strings, and usually for booleans and characters; some also have notations for elements of enumerated types and compound values such as arrays,records, and objects. An anonymous function is a literal for the function type.

In contrast to literals, variables or constants are symbols that can take on one of a class of fixed values, the constant being constrained not to change. Literals are often used to initialize variables, for example, in the following, 1 is an integer literal and the three letter string in "cat" is a string literal:
back to top