-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex53.cpp
More file actions
executable file
·41 lines (29 loc) · 762 Bytes
/
ex53.cpp
File metadata and controls
executable file
·41 lines (29 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
CPSC121-0X
Paul De Palma
depalma
Example 53
*/
//pointer example
#include <iostream>
using namespace std;
int main()
{
//p is a pointer to int
int* p;
int val1, val2;
val1 = 12;
//& is the address operator. Assign the address of val1 to p
p = &val1;
//*p causes the value of what p points to to be stored in val2
//this is called dereferencing
val2 = *p;
cout << "value of what p points to " << *p << endl;
cout << "value of val2 " << val2 << endl;
cout << "p holds the address of val1 " << p << endl;
cout << "val1's address is " << &val1 << endl;
cout << "notice that size of address and size of int differ" << endl;
cout << "size of address " << sizeof(p) << endl;
cout << "size of int " << sizeof(val1) << endl;
return 0;
}