Skip to main content

Chapter 3 - Literals

Literals are data used for representing fixed values or constant variables that cannot be changed or modified. They can be used directly in the code. For example:

const int = 10

The 10 represents the value 10, not a variable named 10.


An integer is known as a numeric literal without a fraction or an exponent. In C programming there are three different types of integer literals:

  • Decimal
    • Eg: 0, -10, 22
  • Octal (base 8 system)
    • Eg: 021, 077, 033
  • Hexadecimal (base 16)
    • Eg: 0x7f, 0x2a, 0x521

Example: change 78 to octal

Divide 78 by 8 until 0

78 รท 8 = 9 R 6

9 รท 8 = 1 R 1

1 รท 8 = 0 R 1

The output will be 116

(Reminder: the remainder from the first division should be in the ones digit)

What the code should look like

void setup(){
Serial.println(78, OCT);
void loop(){


Serial Monitor



In serial.print() enter a number then a comma and OCT. See what the output is in the serial monitor.

Eg: serial.print(78, OCT); should print out 116

Floating-Point Literalsโ€‹

A floating-point literal isa numeric literal that contains a decimal point. It is usually stored in either a decimal form or an exponent form.


Valid EntriesInvalid Entires

Character Literalsโ€‹

  • Character literals are used to store a single character within a single quote (โ€˜xโ€™). To store multiple characters, you will use a character array instead.
Valid EntriesInvalid Entries

String Literalsโ€‹

String literals are similar to character literals, the difference is that string literals are capable of storing multiple characters enclosed in double quotation marks (โ€œbookโ€).

Valid EntriesInvalid Entries

What are Literals used for?โ€‹

Using a literal, you can use the variable name rather than rewriting the value again and again.


Instead of using 11

void setup(){
pinMode(11, OUTPUT);
void loop(){
digitalWrite(11, HIGH);
digitalWrite(11, LOW);

Use a declared integer (Eg. int LED = 11)

int LED = 11; //<---Declare an integer
void setup(){
pinMode(LED), OUTPUT);
void loop(){
digitalWrite(LED), HIGH);
digitalWrite(LED, LOW);

Escape Sequencesโ€‹

Some characters/shortcuts that we used cannot be typed in C programming. For example, enter (for a new line), and tab (for indent). Escape sequences are used to replace of these actions.

Escape SequencesCharacters
\fForm Feed
\tHorizontal Tab
\vVertical Tab
\โ€™Single Quotation mark
\โ€Double Quotation mark
\?Question mark
\0Null Character