Pointer operations

suggest change

There are two operators for pointers: address-of operator (&): Returns the memory address of its operand. Contents-of (dereference) operator (*): Returns the value of the variable located at the address specified by its operator.

int var = 20;
int *ptr;
ptr = &var;

cout << var << endl;
// Outputs 20 (The value of var)

cout << ptr << endl;
// Outputs 0x234f119 (var's memory location)

cout << *ptr << endl;
// Outputs 20(The value of the variable stored in the pointer ptr

The asterisk (*) is used in declaring a pointer for simple purpose of indicating that it is a pointer. Don’t confuse this with the dereference operator, which is used to obtain the value located at the specified address. They are simply two different things represented with the same sign.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Pointers:
* Syntax
* Pointer operations

Table Of Contents
8 Arrays
11 Loops
17 Pointers
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype