dereference a pointer c++ code example

Example 1: dereferencing pointer in cpp

int x = 5;
int *p = &x;

x = x + 4;
x = *p + 4;
*p = *p + 4;

cout << x; //Output is 17

Example 2: c++ dereference a pointer

int number;
int value;
int * pNumber;

number = 5;
pNumber = &number;

assert(pNumber); // check before dereferenceing to prevent errors
value = *pNumber // Use * to dereference the pointer

Example 3: dereference pointer c++

value = *pointer // Use * to dereference the pointer

Tags:

Cpp Example