bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

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

C++ Modify Pointers

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind C++ Modify Pointers?

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";

Modify the Pointer Value

You can also change the pointer's value. But note that this will also change the value of the original variable:

Example

string food = "Pizza";
string* ptr = &food;
// Output the value of food (Pizza) cout << food << "\n"; // Output the memory address of food (0x6dfed4) cout << &food << "\n"; // Access the memory address of food and output its value (Pizza) cout << *ptr << "\n"; // Change the value of the pointer *ptr = "Hamburger"; // Output the new value of the pointer (Hamburger) cout << *ptr << "\n"; // Output the new value of the food variable (Hamburger) cout << food << "\n";

Previous

C++ Dereference

Next

C++ Memory Management