Learn how to use character pointers (`char *`) to work with string literals and manipulate string data.
The relationship between pointers and arrays is particularly significant when it comes to strings in C. Since strings are just null-terminated character arrays, a pointer to a `char` is a very common and efficient way to work with them. You can declare a character pointer and initialize it to point to a string literal. For example, `char *str = "Hello, World!";`. In this case, `str` is a pointer that holds the memory address of the first character, 'H', of the string literal. String literals are typically stored in a read-only section of memory, so while you can read from `str`, attempting to modify its contents (e.g., `str[0] = 'h';`) leads to undefined behavior and will likely crash your program. Using a character pointer is different from declaring a character array like `char arr[] = "Hello, World!";`. In the array version, the string literal is copied into a new block of memory allocated for the array `arr`, and you are free to modify this copy. Pointers are extremely useful for passing strings to functions. Passing a `char *` is very efficient as it only copies the address (typically 4 or 8 bytes), not the entire string. Pointers also make it easy to traverse a string. You can use a `while` loop that continues until the pointer dereferences to the null character (`'\0'`), incrementing the pointer in each iteration to move to the next character. This is a common idiom for string processing in C.