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.

Revisions

  1. TheStygianSun created this gist Sep 28, 2016.
    21 changes: 21 additions & 0 deletions pointerswithstaticvariables.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #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");
    }