Skip to content

Instantly share code, notes, and snippets.

@Codeplaza
Created November 5, 2013 09:05
Show Gist options
  • Save Codeplaza/7315967 to your computer and use it in GitHub Desktop.
Save Codeplaza/7315967 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main ()
{
int firstvalue = 5, secondvalue = 15;
int * p1, * p2;
p1 = &firstvalue; // p1 = address of firstvalue
p2 = &secondvalue; // p2 = address of secondvalue
*p1 = 10; // value pointed by p1 = 10
*p2 = *p1; // value pointed by p2 = value pointed by p1
p1 = p2; // p1 = p2 (value of pointer is copied)
*p1 = 20; // value pointed by p1 = 20
cout << "firstvalue is " << firstvalue << endl;
cout << "secondvalue is " << secondvalue << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment