Data Structures and Algorithms with Object-Oriented Design Patterns in C++

### Dereferencing Pointers

A variable of type is said to point at an object of type T. What this really means is that the value of the variable is the address of another variable of type T. For example, in Figure  the variable q is has type int*, i.e., it is a pointer to an int. The value of p is 1004, which is the address of the variable j.

To access the variable to which a pointer points, we must dereference  the pointer. E.g., to dereference the pointer q we write *q. Whereas q denotes the pointer variable itself, *q denotes the int to which the pointer points.

If we use *q in a context where an r-value is expected, then we get the r-value of the variable to which q points. E.g., since q points to the variable j, the assignment

`i = *q;`
takes the r-value of j (31) and assigns it to i.

Similarly, if we use *q in a context where an l-value is required, then we get the l-value of the variable to which q points. E.g., since q points to the variable j, the assignment

`*q = 31;`
takes the l-value of j (1004) and stores 31 at that location. Notice that the l-value of *q is identical to the r-value of q.