O'Reilly logo

C++ 14 Quick Syntax Reference, Second Edition by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 5

image

Pointers

A pointer is a variable that contains the memory address of another variable, called the pointee.

Creating Pointers

Pointers are declared as any other variable, except that an asterisk (*) is placed between the data type and the pointer’s name. The data type used determines what type of memory it will point to.

int* p; // pointer to an integerint *q; // alternative syntax

A pointer can point to a variable of the same type by prefixing that variable with an ampersand, in order to retrieve its address and assign it to the pointer. The ampersand is known as the address-of operator (&).

int i = 10;p = &i; // address of i assigned ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required