🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C++ Notes
Topic #69

Dereferencing


Get Memory Address and Value

In the example from the previous page, we used the pointer variable to get the memory address of a variable (used together with the & reference operator). However, you can also use the pointer to get the value of the variable, by using the * operator (the dereference operator):

Example

string food = "Pizza";  // Variable declaration
string* ptr =
&food;    // Pointer declaration

//
Reference: Output the memory address of food with the pointer (0x6dfed4)
cout <<
ptr << "\n";

//
Dereference: Output the value of food with the pointer (Pizza)
cout <<
*ptr << "\n";

Note: that the * sign can be confusing here, as it does two different things in our code: When used in declaration (string* ptr), it creates a pointer variable. When not used in declaration, it act as a dereference operator.

Want to go beyond the notes?

Join CodingNow 2.0's C++ course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Dereferencing – FAQs

Quick answers about learning Dereferencing in C++.

This free note from CodingNow 2.0 explains Dereferencing in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on CodingNow 2.0, including Dereferencing, is 100% free with no signup required.
With focused practice, most students grasp Dereferencing in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now