resource: https://www.w3schools.com/cpp/cpp_pointers.asp
C++ Pointers
C++ Pointers Creating Pointers You learned from the previous chapter, that we can get the memory address of a variable by using the & operator: Example string food = "Pizza"; // A food variable of type string cout << food; // Outputs the value of food (Pi
www.w3schools.com
"&" gets you memory address of variables
A pointer is a variable that stores memory address as its value.
A pointer is creted by "*" operator.
string food = "Pizza"; // A food variable of type string
string* ptr = &food; // A pointer variable, with the name ptr, that stores the address of food
Operator "*" does two different things.
1) It creates a pointer variable
2) It gets also the value of the variable.
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";
'정규 강의 > Object-Oriented Data Structures in C++' 카테고리의 다른 글
C++ Copy Assignment Operator (0) | 2019.10.03 |
---|---|
C++ Copy Constructor (0) | 2019.10.03 |
C++ Class Destructors (1) | 2019.10.03 |
1.2 C++ Classes (1) | 2019.09.26 |