⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽

Pointers

Computer Programming C++ / Understanding Memory

A pointer is a type of variable that holds the address of another variable. In other words, it "points to" another varaible. The following video will show you how to create a pointer, as well as dereference pointers, and show you how to access the address of a variable.

Pointers can be used as struct members to avoid the build issues we saw last week. Take a look.

Review Questions

The following are examples of questions similar to what you can expect to see on the next exam.

Hover over a question to show the answer.
  1. What is the syntax for creating a pointer? data-type *name;
  2. What is the ampersand (&) used for when not in a parameter list? Getting the address of a variable. It's the "Address of" operator.
  3. What does the following code do? int *pNumber; Creates a pointer to an integer.
  4. What does the following code do? pNumber = &number; Gets the address of "number" and assigns it to "pNumber."
  5. What does the following code do? cout << *pNumber; Prints the value stored at the location that pNumber points to.
  6. What is wrong with the following code? int *pNumber = &10; 10 is not a variable (it's a literal), therefore you cannot get the address of it.
⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽
© Ryan Appel