bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/C++/C++ Tutorial
C++•C++ Tutorial

C++ Memory Address

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind C++ Memory Address?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ food = "Pizza";
3Order

Put the learning moves in the order that makes the concept easiest to apply.

To access it, use the & operator, and the result will represent where the variable is stored:
When a variable is created in C++, a memory address is assigned to the variable.
In the example from the earlier example, the & operator was used to create a reference variable.

Memory Address

In the example from the earlier example, 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:

Example

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.

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 .

Previous

C++ Enumeration (enum)

Next

C++ Pointers