Learn how to define constants and understand different types of literals.
A literal is a value that is written directly into the source code. For example, in the statement `int x = 100;`, `100` is an integer literal. Literals can be of any basic data type. `3.14` is a double literal, `'A'` is a character literal, and `"hello"` is a string literal. Sometimes, you need to store a value that should not be changed throughout the program's execution. These are called constants. C++ provides two main ways to define constants. The first is using the `const` keyword. When you declare a variable with `const`, you are telling the compiler that its value is read-only and cannot be modified after initialization. For example, `const double PI = 3.14159;`. Any attempt to change the value of `PI` later in the code will result in a compilation error. This makes your code safer and more self-documenting, as it clearly communicates the intent that a value should not change. The second method is using the `#define` preprocessor directive, like `#define PI 3.14159`. However, using `const` is generally preferred in modern C++ because it is type-safe and respects scope, whereas `#define` is a simple text substitution performed by the preprocessor before compilation, which can sometimes lead to unexpected errors.