Created
September 28, 2016 15:21
-
-
Save dmcleish91/93f3a33c819c0d3a1fc49e1b76c7a10f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| void change(string* change_first, string* change_last) // in this function we created a pointer | |
| { | |
| *change_first = "Master"; // this allows us to change the variable because we know its memory address | |
| *change_last = "piece"; | |
| } | |
| int main() | |
| { | |
| string first = "first"; // declaring some normal variables | |
| string last = "last"; | |
| cout << first << last << "\n"; | |
| change(&first, &last); // we use & to make the pointer reference the variable | |
| cout << first << last << "\n"; | |
| system("pause"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment