Literally!

In C, literals are ways to express specific values within the source code. Different types of literals include integer, floating-point, character, and string literals.

Here's a sample program with explanations:

#include <stdio.h>

int main() {
    // Integer literals
    int decimal = 10;      // Decimal integer literal
    int octal = 012;       // Octal integer literal (prefixed with 0)
    int hexadecimal = 0xA; // Hexadecimal integer literal (prefixed with 0x)

    // Floating-point literals
    float floatingPoint = 3.14;  // Floating-point literal
    double exponential = 1.5e2;  // Exponential notation (1.5 * 10^2)

    // Character literals
    char singleChar = 'A';       // Character literal (enclosed in single quotes)
    char escapedChar = '\n';     // Escaped character (newline in this case)

    // String literal
    char* stringLiteral = "Hello, World!"; // String literal (enclosed in double quotes)

    // Printing the values
    printf("Integer literals: decimal = %d, octal = %o, hexadecimal = %x\n", decimal, octal, hexadecimal);
    printf("Floating-point literals: floatingPoint = %f, exponential = %lf\n", floatingPoint, exponential);
    printf("Character literals: singleChar = %c, escapedChar = %c\n", singleChar, escapedChar);
    printf("String literal: %s\n", stringLiteral);

    return 0;
}

Explanation of each type:

  1. Integer Literals: These are the most basic type of literals and can be expressed in decimal (base 10), octal (base 8, prefixed with 0), or hexadecimal (base 16, prefixed with 0x).

  2. Floating-Point Literals: Represent real numbers and can include a decimal point. They can also be expressed in exponential form (e.g., 1.5e2 is equivalent to 1.5 * 10^2).

  3. Character Literals: Represented by a single character enclosed in single quotes. Special characters (like newline \n, tab \t) can be represented using escape sequences.

  4. String Literals: A sequence of characters enclosed in double quotes. They are actually arrays of characters ending with a null character '\0'.