back
Pointers and Character Arrays
First step, open up the PowerPoint presentation located in the public directory in the folder for period two called "C++ Stuff." The name of the PowerPoint presentation is "pointers_2."

After gaining an understanding of pointers, the idea of character arrays may be easier to understand. Recall that you create a character array as follows:

char word[10] = "Skyline";

When you create a character array, you are actually making what is called a pointer constant. The name "Skyline" points to the location of the very first character in your array. This is what it looks like:



Names and letters still come down to simple memory addresses when all is said and done. Pointers are what makes it all happen. Now, to prove how this all works. Copy and paste this example in your compiler. Execute it and leave it on the screen.



[example #1]

What you see is a simple character array. Now, let's change a single character using a technique called subscript notationas follows:

[example #2]

Notice how we change one character by accessing the first letter of the array. Recall that an array always starts with zero as in this diagram:



Assignment 1
Create four cout statements in your program that each change one letter of a word.

We can do the same thing using a pointer. Take a look at this example:

[example #3]

Assignment 2
Do the same thing you did in assignment one with a pointer.