-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpointers.cpp
More file actions
22 lines (19 loc) · 1 KB
/
pointers.cpp
File metadata and controls
22 lines (19 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main() {
int *pc, c; // pointer pc declared
c = 5;
cout << "Address of c (&c): " << &c << endl; // &c displays the reference to the memory address
cout << "Value of c (c): " << c << endl << endl;
pc = &c; // Pointer pc holds the memory address of variable c
cout << "Address that pointer pc holds (pc): "<< pc << endl;
cout << "Content of the address pointer pc holds (*pc): " << *pc << endl << endl;
c = 11; // The content inside memory address &c is changed from 5 to 11.
cout << "Address pointer pc holds (pc): " << pc << endl;
cout << "Content of the address pointer pc holds (*pc): " << *pc << endl << endl; /* address remains the same
but the value of c gets changed on the same address*/
*pc = 2; // changing value of c to 2
cout << "Address of c (&c): " << &c << endl; // output c(address)
cout << "Value of c (c): " << c << endl << endl; // value of c = 2
return 0;
}