Skip to content

Commit 2cf549b

Browse files
committed
fix: Update correct video links in C++ Strings guide
1 parent ccfd7ac commit 2cf549b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

26.How Strings Work in C++.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
## How Strings Work in C++ (and how to use them)
22

3-
**Video Link:** [C++ Strings ](https://youtu.be/6OVQ8nh3KP0)
3+
**Video Link:** [C++ Strings ](https://youtu.be/ijIxcB9qjaU)
44

5-
**Playlist Link:** [C++ Tutorial Playlist by The Cherno](https://www.youtube.com/watch?v=6OVQ8nh3KP0&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=10)
5+
**Playlist Link:** [C++ Tutorial Playlist by The Cherno](https://www.youtube.com/watch?v=ijIxcB9qjaU&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=10)
66

7-
### 📌 Prerequisites (Mentioned at [0:06](https://youtu.be/6OVQ8nh3KP0?t=6))
7+
### 📌 Prerequisites (Mentioned at [0:06](https://youtu.be/ijIxcB9qjaU?t=6))
88

99
* It's helpful to have watched the previous videos on:
1010
* Pointers ([Episode 8](https://www.youtube.com/watch?v=DTxHNJHI7Ys&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=8))
1111
* Arrays ([Episode 9](https://www.youtube.com/watch?v=ENDaJi08jCU&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=9))
1212
* Why? Because strings are closely related to both concepts.
1313

14-
### 🤔 What is a String? (General Concept) ([0:21](https://youtu.be/6OVQ8nh3KP0?t=21))
14+
### 🤔 What is a String? (General Concept) ([0:21](https://youtu.be/ijIxcB9qjaU?t=21))
1515

1616
* A string is essentially a sequence or group of characters.
1717
* Characters can be:
@@ -21,42 +21,42 @@
2121
* Basically, a string represents **text**.
2222
* Representing text is fundamental in programming for user interfaces, file handling, data processing, etc.
2323

24-
### 💡 How Strings Work: The Basics ([1:08](https://youtu.be/6OVQ8nh3KP0?t=68))
24+
### 💡 How Strings Work: The Basics ([1:08](https://youtu.be/ijIxcB9qjaU?t=68))
2525

2626
* To understand strings, you first need to understand how *characters* work.
27-
* **Characters (`char`) in C++:** ([1:53](https://youtu.be/6OVQ8nh3KP0?t=113))
27+
* **Characters (`char`) in C++:** ([1:53](https://youtu.be/ijIxcB9qjaU?t=113))
2828
* The `char` data type is used.
2929
* Typically, `char` is **1 byte** (8 bits) of memory.
3030
* This 1-byte size is often used for low-level memory manipulation (like pointer arithmetic in bytes or creating memory buffers).
31-
* **Character Encoding:** ([2:00](https://youtu.be/6OVQ8nh3KP0?t=120))
31+
* **Character Encoding:** ([2:00](https://youtu.be/ijIxcB9qjaU?t=120))
3232
* How characters (letters, symbols) are mapped to numbers (and thus, bytes).
3333
* **ASCII** is the most basic standard, using 1 byte (technically 7 bits, extended ASCII uses 8). It can represent 256 different characters (0-255).
3434
* This is enough for English letters (uppercase/lowercase), numbers, and common symbols.
35-
* **Limitation:** ASCII cannot represent characters from many other languages (e.g., Japanese, Chinese, Russian, Korean) because there are far more than 256 unique characters globally. ([3:22](https://youtu.be/6OVQ8nh3KP0?t=202))
35+
* **Limitation:** ASCII cannot represent characters from many other languages (e.g., Japanese, Chinese, Russian, Korean) because there are far more than 256 unique characters globally. ([3:22](https://youtu.be/ijIxcB9qjaU?t=202))
3636
* Other encodings exist (UTF-8, UTF-16, UTF-32 - part of Unicode) to handle this, often using more than 1 byte per character. *This video focuses on the basic ASCII/`char` concept.*
3737

38-
### ⛓️ C-Style Strings: Character Pointers & Arrays ([2:59](https://youtu.be/6OVQ8nh3KP0?t=179))
38+
### ⛓️ C-Style Strings: Character Pointers & Arrays ([2:59](https://youtu.be/ijIxcB9qjaU?t=179))
3939

4040
* Traditionally (in C, and still usable in C++), strings are represented as arrays of characters, often manipulated via pointers.
4141
* **String Literals:** When you write text in double quotes like `"Cherno"`, this is a string literal.
4242
* Example: `const char* name = "Cherno";`
4343
* `name` is a pointer (`char*`) pointing to the first character ('C') of a sequence of characters stored somewhere in the program's memory.
4444
* This memory location for string literals is often **read-only**.
45-
* **Why `const`?** ([5:54](https://youtu.be/6OVQ8nh3KP0?t=354))
45+
* **Why `const`?** ([5:54](https://youtu.be/ijIxcB9qjaU?t=354))
4646
* Because string literals are often in read-only memory, trying to modify them can cause a crash.
4747
* Declaring the pointer as `const char*` makes the *data pointed to* constant (read-only from the perspective of this pointer). This helps prevent accidental modification attempts.
4848
* Example of what **NOT** to do:
4949
```c++
5050
char* name = "Cherno"; // Problematic: Assigning literal to non-const pointer
5151
name[2] = 'a'; // CRASH! Trying to write to read-only memory.
5252
```
53-
* **Null Termination:** ([8:07](https://youtu.be/6OVQ8nh3KP0?t=487))
53+
* **Null Termination:** ([8:07](https://youtu.be/ijIxcB9qjaU?t=487))
5454
* How does the program know where a C-style string ends if it only has a pointer to the start?
5555
* Answer: A special **null terminator character** (`\0`) is automatically added at the end of string literals.
5656
* This character has an ASCII value of **0**.
5757
* Functions working with C-style strings (like printing) read characters sequentially from the starting address until they encounter this null byte (value 0).
58-
* Memory View: `"Cherno"` in memory looks like `C h e r n o \0` (represented by their byte values, with the last one being `00`). ([7:21](https://youtu.be/6OVQ8nh3KP0?t=441))
59-
* **Manual Char Arrays:** ([8:48](https://youtu.be/6OVQ8nh3KP0?t=528))
58+
* Memory View: `"Cherno"` in memory looks like `C h e r n o \0` (represented by their byte values, with the last one being `00`). ([7:21](https://youtu.be/ijIxcB9qjaU?t=441))
59+
* **Manual Char Arrays:** ([8:48](https://youtu.be/ijIxcB9qjaU?t=528))
6060
* You can create strings using explicit char arrays.
6161
* Example (Incorrect - Missing Null Terminator):
6262
```c++
@@ -74,7 +74,7 @@
7474
```
7575
* **Key takeaway:** If manually creating char arrays for strings, always allocate one extra byte for the null terminator and ensure it's set to 0 or `\0`.
7676

77-
### ✨ The C++ `std::string` Way ([11:03](https://youtu.be/6OVQ8nh3KP0?t=663))
77+
### ✨ The C++ `std::string` Way ([11:03](https://youtu.be/ijIxcB9qjaU?t=663))
7878

7979
* C++ provides a much more convenient and safer way to handle strings via the Standard Library.
8080
* **Include Header:**
@@ -100,7 +100,7 @@
100100
* **Easier:** Simpler syntax, less manual memory management.
101101
* **Safer:** Reduces risks of buffer overflows and memory errors common with C-style strings.
102102
* **Functionality:** Provides many useful member functions (e.g., finding length, appending, searching).
103-
* **Concatenation (Appending Strings):** ([14:08](https://youtu.be/6OVQ8nh3KP0?t=848))
103+
* **Concatenation (Appending Strings):** ([14:08](https://youtu.be/ijIxcB9qjaU?t=848))
104104
* **Problem:** `std::string name = "Cherno" + " hello!";` // ERROR!
105105
* Reason: Both `"Cherno"` and `" hello!"` are `const char*` (C-style string literals/pointers). C++ doesn't define how to add two `const char*` pointers together in this context.
106106
* **Solution 1 (Using `+=`):**
@@ -116,7 +116,7 @@
116116
std::cout << name << std::endl; // Outputs "Cherno hello!"
117117
```
118118
* This works because `std::string("Cherno")` creates a `std::string` object. The `+` operator *is* overloaded for `std::string` + `const char*`.
119-
* **Finding Substrings:** ([15:14](https://youtu.be/6OVQ8nh3KP0?t=914))
119+
* **Finding Substrings:** ([15:14](https://youtu.be/ijIxcB9qjaU?t=914))
120120
* Use the `.find()` member function.
121121
* Example:
122122
```c++
@@ -128,7 +128,7 @@
128128
std::cout << "Found 'no'!" << std::endl;
129129
}
130130
```
131-
* **Getting Size/Length:** ([13:45](https://youtu.be/6OVQ8nh3KP0?t=825))
131+
* **Getting Size/Length:** ([13:45](https://youtu.be/ijIxcB9qjaU?t=825))
132132
* Use the `.size()` member function.
133133
* Example:
134134
```c++
@@ -137,7 +137,7 @@
137137
```
138138
* This is much easier than using C-style functions like `strlen()`.
139139

140-
### 👉 Passing Strings to Functions ([16:13](https://youtu.be/6OVQ8nh3KP0?t=973))
140+
### 👉 Passing Strings to Functions ([16:13](https://youtu.be/ijIxcB9qjaU?t=973))
141141

142142
* How should you pass `std::string` objects to functions?
143143
* **Option 1: Pass by Value (Generally BAD for strings)**
@@ -162,7 +162,7 @@
162162
* **Benefit:** Highly efficient (no copying) and safe (prevents accidental modification).
163163
* **Rule of Thumb:** If a function only needs to *read* a string, pass it by `const std::string&`.
164164

165-
### 🙏 Conclusion ([17:54](https://youtu.be/6OVQ8nh3KP0?t=1074))
165+
### 🙏 Conclusion ([17:54](https://youtu.be/ijIxcB9qjaU?t=1074))
166166

167167
* Strings are fundamental for text representation.
168168
* C-style strings (`char*`, char arrays) require manual null termination and careful memory management.

0 commit comments

Comments
 (0)