master
parent
43033a2a6e
commit
579c9d18f1
|
@ -229,22 +229,22 @@ I must **emphasise** this.
|
||||||
|
|
||||||
|
|
||||||
// more pointers
|
// more pointers
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
int firstvalue = 5, secondvalue = 15;
|
int firstvalue = 5, secondvalue = 15;
|
||||||
int * p1, * p2;
|
int * p1, * p2;
|
||||||
|
|
||||||
p1 = &firstvalue; // p1 = address of firstvalue
|
p1 = &firstvalue; // p1 = address of firstvalue
|
||||||
p2 = &secondvalue; // p2 = address of secondvalue
|
p2 = &secondvalue; // p2 = address of secondvalue
|
||||||
*p1 = 10; // value pointed to by p1 = 10
|
*p1 = 10; // value pointed to by p1 = 10
|
||||||
*p2 = *p1; // value pointed to by p2 = value pointed to by p1
|
*p2 = *p1; // value pointed to by p2 = value pointed to by p1
|
||||||
p1 = p2; // p1 = p2 (value of pointer is copied)
|
p1 = p2; // p1 = p2 (value of pointer is copied)
|
||||||
*p1 = 20; // value pointed to by p1 = 20
|
*p1 = 20; // value pointed to by p1 = 20
|
||||||
|
|
||||||
cout << "firstvalue is " << firstvalue << '\n';
|
cout << "firstvalue is " << firstvalue << '\n';
|
||||||
cout << "secondvalue is " << secondvalue << '\n';
|
cout << "secondvalue is " << secondvalue << '\n';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue