<<< Pointer dereference *ptr | Index | Pointer summary >>> |
int main( ) { int x = 1; int* ptr; // (1) ptr is a pointer to an integer ptr = &x; // (2) store address of x in ptr *ptr = 100; // (3) store new value at the address pointed by ptr return 0; }
Here, the asterisk * is a type modifier, not a dereference.
Ampersand & operator returns an address of a variable: ptr = &x;
Finally, an asterisk *ptr dereferences the pointer, providing access to the variable in memory:
*ptr = 100;
Dereference operator *ptr is also known as indirection operator.
<<< Pointer dereference *ptr | Index | Pointer summary >>> |