More on Character Arrays (tk10.2) All character arrays use a pointer When you declare a character array, the name you give the array is actually a pointer constant. A pointer constant is like a pointer variable, except you cannot change what it points to. The strcpy function is required to assign a string to a character array so it won't get confused when pointer constants are used. Using Subscript notation C++ allows you to access any character in a character array individually using a method called subscript notation. Subscript notation looks like the syntax you use when declaring a character array. Example: #include void main() { char my_word[5] = "book"; cout << my_word << '\n'; } Characters of a character array are stored together in memory. The acharacters of the array are numbered, beginning with zero. So a five-character array is numbered 0 through 4. Using subscript notation you can change the first character in the array using a statement like: my_word[0] = 't'; The first character is changed to a 't' because the first character is at position 0. The first character in the array is where the pointer points. To access the fourth character, however, you must move three times. Be careful when accessing characters in an array individually. The compiler will not prevent you from going beyond the length of your array. You could end up changing other data in memory instead of your array. If the null terminator of your string is changed to another aharacter, the compiler will allow it and errors will result. Using the * operator in character arrays Because characters occupy one byte of memory, it makes sense that the second character of the array is stored at my_word + 1. Using the dereferencing operator and this knowledge of how the array is stored, you can change the fourth character in the array using a statement like: *(my_word + 3) = 'n'; You can see the subscript notation makes for more readable code than the deferencing operator. Short Answer: 1. The name of a character array is what kind of pointer? 2. Why can't you assign a string to a character array using the assignment operator? 3. What is the name of the method that allows you to access individual characters of a character array using brackets([])? 4. Given the character array declared as char A[8] = "ABCDEFG"; what character is returned by A[2]? 5. Using the same character array you used for question 4, what would be the resulting string if the following statement were executed? A[1] = 'X'; Write a program that declares a character array named alphabet and initializes the array to "ABCDEFGHIJKLMNOPQRSTUVWXYZ." In your program, include a loop that replaces one character of the array at a time with the lowercase letters a-z. Print the character array to the screen during each iteration of the loop. Hint: Remember that a character array is an array of integer values. Use ASCII values to make the changes. Save the source code file as ALPHABET.CPP.