Literals are the actual values assigned to variables. They are data items that do not have a name but represent a specific value directly in the code.
Integer Literals: Plain numbers without decimals (e.g., 100, -25).
Floating-point Literals: Numbers with decimal points (e.g., 3.14, 10.5).
Character Literals: Single characters enclosed in single quotes (e.g., 'A', '$').
String Literals: Sequences of characters enclosed in double quotes (e.g., "Hello EMBLAB").
Constants are variables whose values cannot be modified once they are defined. If you try to change a constant, the compiler will throw an error. There are two primary ways to define constants in C:
This is the most common way to declare a constant. It follows the standard variable declaration but starts with const.
const float PI = 3.14;
Benefit: The compiler knows the data type, which helps with debugging and memory management.
This defines a "symbolic constant." The preprocessor replaces every instance of the name with the value before the code is even compiled.
#define MAX_SPEED 120
Difference: It does not use memory like a variable and does not require a semicolon at the end.
| Feature | const Variable | #define Constant |
| Type Checking | Performed by compiler | No type checking |
| Scope | Respects scope (local/global) | Global (until #undef) |
| Memory | Occupies memory | No memory (text replacement) |
| Syntax | const int X = 10; | #define X 10 |
C uses special character literals called Escape Sequences to represent non-printable characters or characters with special meanings:
\n : Newline (moves cursor to the next line)
\t : Horizontal Tab
\\ : Backslash
\" : Double Quote
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION