-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq2.cpp
More file actions
26 lines (23 loc) · 688 Bytes
/
Copy pathq2.cpp
File metadata and controls
26 lines (23 loc) · 688 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
/*
Declare an array of elements “arr[5]”. Declare a pointer variable “ptr”.
Display the address of each element using array. Display the address of each element using pointer.
*/
#include<iostream>
using namespace std;
int main()
{
int arr[5] = { 5,10,15,20,25 };
int* ptr;
cout << "Address of elements using array\n" << endl;
for (int i = 0; i < 5; i++) {
cout << "Address of Element " << i << " using array:" << &arr[i] << endl;
}
cout << "\nAddress of elements using pointers\n" << endl;
for (int i = 0; i < 5; i++) {
ptr = &arr[i];
cout << "For Element " << i << " Address is:" << ptr << endl;
}
cout << endl;
system("pause");
return 0;
}