Pointer Value and the Address-of Operator &

You will be familiarized with the pointer syntax in D in this lesson.

We'll cover the following

Values of pointers

Being variables themselves, pointers also have values. The default value of a pointer is the special value null, which means that the pointer is not pointing at any variable yet (i.e., does not provide access to any variable).

To make a pointer provide access to a variable, the value of the pointer must be set to the address of that variable. The pointer starts pointing at the variable that is at that specific address. From now on, we will call that variable the pointee.

The & operator, which we have used many times before with readf, was also briefly mentioned in the value types and reference types chapter. This operator produces the address of the variable that is written after it. Its value can be used when initializing a pointer:

int myVariable = 180;
int * myPointer = &myVariable;

Initializing myPointer by the address of myVariable makes myPointer point at myVariable.

The value of the pointer is the same as the address of myVariable:

Get hands-on with 1000+ tech skills courses.