-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpointers.cpp
More file actions
25 lines (19 loc) · 738 Bytes
/
pointers.cpp
File metadata and controls
25 lines (19 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
int main() {
std::string some_word = "foot";
std::string* some_word_ptr = &some_word;
(*some_word_ptr).append("ball");
// Prints "football"
std::cout << "Output after first append:" << std::endl;
std::cout << "\t" << some_word << std::endl;
std::cout << "\t" << *some_word_ptr << std::endl;
// Equivalent to the call above
some_word_ptr->append("s");
// Prints "footballs"
std::cout << "Output after second append:" << std::endl;
std::cout << "\t" << some_word << std::endl;
std::cout << "\t" << *some_word_ptr << std::endl;
// Prints a memory address
std::cout << "Memory address:" << std::endl;
std::cout << "\t" << some_word_ptr << std::endl;
}