-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpointerValues.cpp
More file actions
30 lines (24 loc) · 856 Bytes
/
pointerValues.cpp
File metadata and controls
30 lines (24 loc) · 856 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
#include <iostream>
using namespace std;
int main() {
int a = 8;
int b = 16;
//declare and initialize a pointer variable to point to a variable
//datatype* pointerName = &variableName;
int* aPtr = &a;
int* bPtr = &b;
//dynamic hexadecimal output of the pointer address
cout << "Addresses of pointers: " << endl;
cout << "aPtr: " << &aPtr << endl;
cout << "bPtr: " << &bPtr << endl << endl;
//dynamic hexadecimal output of the pointer value
cout << "Values of pointers: " << endl;
cout << "aPtr: " << aPtr << endl;
cout << "bPtr: " << bPtr << endl << endl;
//value in address pointed to by pointer
//*pointerName dereferences the pointer
cout << "Values pointed to by pointers: " << endl;
cout << "a:" << *aPtr << endl;
cout << "b:" << *bPtr << endl << endl;
return 0;
}