Ready to practice?
Sign up to access interactive coding exercises and track your progress.
Beginner
minutes
Constants and Text Terminology
Overview of constants and text concepts in this chapter.
Last updated:
This reference provides an overview of constants and text terminology you'll encounter in this chapter. Use it as a quick lookup guide.
Constants
| Term | Definition | Example |
|---|---|---|
| Constant | A value that cannot be changed after initialization | const int maxSize{100}; |
| const | Keyword that makes a variable read-only | const double pi{3.14159}; |
| constexpr | Keyword for compile-time constant expressions | constexpr int size{10}; |
| Named constant | A constant with a descriptive identifier | const int daysInWeek{7}; |
| Magic number | Unexplained literal value in code (bad practice) | if (x > 42) without context |
| Symbolic constant | Named constant replacing magic numbers | const int maxRetries{42}; |
Literals
| Term | Definition | Example |
|---|---|---|
| Literal | A fixed value written directly in code | 42, 3.14, "hello" |
| Integer literal | A whole number value | 42, 0xFF, 0b1010 |
| Floating-point literal | A decimal number value | 3.14, 2.5e10 |
| Character literal | A single character in single quotes | 'A', '\n' |
| String literal | Text in double quotes | "Hello, World!" |
| Boolean literal | true or false keyword | true, false |
| Literal suffix | Type specifier after a literal | 42L, 3.14f, 100ULL |
Numeral Systems
| Term | Definition | Example |
|---|---|---|
| Decimal | Base-10 number system | 255 |
| Binary | Base-2 number system (prefix 0b) | 0b11111111 (255) |
| Octal | Base-8 number system (prefix 0) | 0377 (255) |
| Hexadecimal | Base-16 number system (prefix 0x) | 0xFF (255) |
| Digit separator | Single quotes for readability | 1'000'000 |
Compile-Time Concepts
| Term | Definition | Example |
|---|---|---|
| Constant expression | Expression evaluable at compile time | constexpr int x{5 + 3}; |
| Compile-time constant | Value known during compilation | constexpr int size{10}; |
| Runtime constant | Value determined during execution | const int input{getUserInput()}; |
| As-if rule | Compiler can optimize if behavior unchanged | Replacing x * 2 with x << 1 |
| Constant folding | Compiler evaluates constant expressions | 3 + 4 becomes 7 |
| Inline expansion | Replacing function call with function body | Optimization for small functions |
String Types
| Term | Definition | Example |
|---|---|---|
| std::string | Dynamic string class from standard library | std::string name{"Alice"}; |
| std::string_view | Non-owning view into a string (read-only) | std::string_view sv{"hello"}; |
| C-style string | Null-terminated character array | const char* s = "hello"; |
| Null terminator | Character marking end of C-string (\0) |
Hidden at end of string literals |
| Empty string | String with no characters | "" or std::string{} |
String Operations
| Term | Definition | Example |
|---|---|---|
| Concatenation | Joining strings together | "Hello" + " " + "World" |
| Length/Size | Number of characters in a string | str.length(), str.size() |
| Capacity | Total storage allocated for string | str.capacity() |
| Substring | A portion of a string | str.substr(0, 5) |
| String view | Lightweight, non-owning string reference | std::string_view sv{str}; |
String Characteristics
| Term | Definition | Example |
|---|---|---|
| Mutable | Can be modified after creation | std::string is mutable |
| Immutable | Cannot be modified after creation | String literals are immutable |
| Dynamic allocation | Memory allocated at runtime | std::string grows as needed |
| View | Reference to existing data without copying | std::string_view doesn't copy |
| Dangling | Reference to data that no longer exists | string_view to temporary string |
Constants and Text Terminology - Quiz
Test your understanding of the lesson.
7 questions
10 minutes
60% to pass
Lesson Discussion
Share your thoughts and questions
💬
No comments yet. Be the first to share your thoughts!