Recommend viewing at 720p HD full screen. Post any questions or comments in the discussion section below. To view a modified text transcript of this lesson, click here.
I am taking this review process slowly, to make sure that each concept is entirely mastered before we proceed. The next topic I want to review about pointers involves the differences between using the * character with a pointer.
The * character means exactly two things concerning a pointer. It means either "Make this variable a pointer", or it means: "What is at the address of the pointer". There is no other possibility.
When you first create a pointer, you use the * character and it means "I am making a pointer." That is all it means.
After a pointer is created, even if it has not yet been assigned, the * character takes on new meaning. It now means for the rest of your program: "what is at the address of".
char*my_pointer = ... // <--- Here and *only* here, the // * character means "I am creating // a pointer. ... ... // <--- For the rest of the program, the ... // * character when used with this pointer will ... // mean "what is at the address contained in the pointer"
So that covers the * character. At this stage it should be very clear to you that any time you ever see the * character used with a pointer, other than its creation, it means "what is at the address of" the memory address in the pointer.
Now, there is a term for this process. It is called dereferencing. This is the act of "seeing" what is at the memory address contained in a pointer. For example:
char my_character ='a'; char*my_pointer =&my_character; printf("The character is %c ",*my_pointer);
In the third line, we are seeing the * character being used, and it is not part of the creation of the pointer, therefore the * character means we are asking for "what is at the memory address" of the pointer. Which is of course, the character 'a'.
Now, lastly lets review the & character in the context of pointers. It simply means "address of" and it will give you the memory address that anything resides at. You can use the & "address of" operator with variables, pointers, arrays, array elements, and more.
It might help to think of the & operator as a function that returns a memory address.