Skip to content

Instantly share code, notes, and snippets.

@dmcleish91
Created September 28, 2016 15:21
Show Gist options
  • Save dmcleish91/93f3a33c819c0d3a1fc49e1b76c7a10f to your computer and use it in GitHub Desktop.
Save dmcleish91/93f3a33c819c0d3a1fc49e1b76c7a10f to your computer and use it in GitHub Desktop.
#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