Dereferencing a Pointer in C/C++



Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being pointed, so this is called dereferencing of pointers.

int main() {
 int a = 7, b ;
 int *p; // Un-initialized Pointer
 p = &a; // Stores address of a in ptr
 b = *p; // Put Value at ptr in b
}

Here, address in p is basically address of a variable.

Complete tutorial on dereferencing: C++ Dereferencing

Updated on: 2024-11-08T16:56:54+05:30

22K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements