Jump to content

C++ Lessons : 20.1. Memory Address


Recommended Posts

  • Manager

Memory Address

In the example from the previous page, the & operator was used to create a reference variable. But it can also be used to get the memory address of a variable; which is the location of where the variable is stored on the computer.

When a variable is created in C++, a memory address is assigned to the variable. And when we assign a value to the variable, it is stored in this memory address.

To access it, use the & operator, and the result will represent where the variable is stored:


string food = "Pizza";

cout << &food; // Outputs 0x6dfed4


Note: The memory address is in hexadecimal form (0x..). Note that you may not get the same result in your program.

And why is it useful to know the memory address?

References and Pointers (which you will learn about in the next chapter) are important in C++, because they give you the ability to manipulate the data in the computer's memory - which can reduce the code and improve the performance.

These two features are one of the things that make C++ stand out from other programming languages, like Python and Java.



Click! : adelinrzo

Click! quiixx.

Click! : raizo


Guardian of Leaks!


image.png.3ca1bf60c26a3523b93df92ea8521802.png (24.01.2023)

image.png.990bdf55e8ebaad7e92cc11967598b8d.png (12.03.2023)

image.png.25e5d76f6f7de46f49423812d3d500a3.png (30.03.2023)

Link to comment
Share on other sites

  • quix locked this topic
This topic is now closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...