You are on page 1of 4

What are Literals?

  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.
 Literals are used as particular values within the source code of a program.
 For Example: a=5; 5 in this piece of code is a literal constant.

Literal Constants
 Literal constants can be :
 Integer numerals
 Floating-point numerals
 Characters
 Strings
 Boolean values

Integer numerals
 Integer numerals are constant and are also called Decimal numerals.
 For Example:
 235
 612
 18
 29
Floating-point numerals
 Floating-point numerals are numbers with decimals, fraction, and/or exponents.
 For example:
 3.14159 // 3.14159
 6.02e23 // 6.02 x 10 ^23

Character and String literals


 Character and String literals are non-numeric constant literals like:
 ‘z’- character
 ‘j’- character
 ‘a’- character
 “Jasmin”- string
 “Hello World”- string

Difference between Character and String


 Character represents a single character constant.
 While a String literal is composed of several characters.
 A Character is enclosed with single quotation marks (‘f’).
 String literal has double quotation marks(“Hello world“).

Boolean Literals
 Boolean Literals can have either a true or false.
 Example:
<< true << '\n‘
false << '\n‘
 Output:
True-1
False-0
Group
Report
Submitted by: Group 3

Members:
Kahn Xavier Nathaniel Domingo
John Benedict Alcantara
Lance Tristan Belen
John Michael Ilagan
Abigail Daaca
Rein Julien Tandang
Angela Kate Bundalian
Juliann Fandialan
Trisha Marie Pacia
Daniel Luis Codilla
Programming
Using Visual
Studio

You might also like