-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_pointers.cpp
More file actions
31 lines (25 loc) · 855 Bytes
/
Copy patharray_pointers.cpp
File metadata and controls
31 lines (25 loc) · 855 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
//using of array with the pointers.
#include <iostream>
using namespace std;
int main(){
int a[ 3 ] = { 1, 2, 3 };
int *p = a; // p = &a[ 0 ];
cout << p[ 1 ] << endl; // p[ 1 ] = 2 because pointer 'p' and array 'a' have the same adresses.
cout << "before of accessed the array elements with pointer." << endl;
cout << "a array : ";
for ( int i = 0; i < 3; i++) //
cout << a[ i ] << " ";
cout << "\np array : ";
for ( int i = 0; i < 3; i++)
cout << p[ i ] << " ";
p[ 2 ] = 100;
p[ 1 ] = 10;
cout << "\n\nafter of accessed the array elements with pointer." << endl;
cout << "a array : ";
for ( int i = 0; i < 3; i++) //
cout << a[ i ] << " ";
cout << "\np array : ";
for ( int i = 0; i < 3; i++)
cout << p[ i ] << " ";
return 0;
}