-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass22.cpp
More file actions
46 lines (38 loc) · 1.05 KB
/
class22.cpp
File metadata and controls
46 lines (38 loc) · 1.05 KB
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
42
43
44
45
46
#include <iostream>
using namespace std;
void swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
//question 1
cout<< "QUESTION 1" << endl;
int a = 9;
int* ptr = &a;
int** ptr2 = &ptr;
cout << "Value of a is: " << a << endl;
cout << "Address of a is: " << ptr << endl;
cout << "Value on ptr2 is: " << *ptr2 << endl;
//question 2
cout << "\nQUESTION 2" << endl;
float f = 3.14;
float* fPtr = &f;
cout << "Value of f is: " << f << endl;
cout << "Address of f is: " << fPtr << endl;
//question 3
cout << "\nQUESTION 3" << endl;
int x = 10, y = 20;
cout << "Before swap: x = " << x << ", y = " << y << endl;
swap(&x, &y);
cout << "After swap: x = " << x << ", y = " << y << endl;
//question 4
cout << "\nQUESTION 4" << endl;
int arr[5] = {1, 2, 3, 4, 5};
int* arrPtr = arr;
cout << "Array elements: ";
for (int i = 0; i < 5; i++) {
cout << *(arrPtr + i) << " ";
}
return 0;
}