-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12arrays_pointer.cpp
More file actions
49 lines (43 loc) · 1.1 KB
/
Copy path12arrays_pointer.cpp
File metadata and controls
49 lines (43 loc) · 1.1 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
47
48
49
#include <iostream>
using namespace std;
int main(){
//example of array
int mathmarks[4];
mathmarks[0] = 56;
mathmarks[1] = 768;
mathmarks[2] = 867;
mathmarks[3] = 5667;
cout<<"these were math marks"<<endl;
cout<<mathmarks[0]<<endl;
cout<<mathmarks[1]<<endl;
cout<<mathmarks[2]<<endl;
cout<<mathmarks[3]<<endl;
cout<<endl;
//short method
int marks[4] = {12, 34, 65 ,78};
cout<<"these are marks"<<endl;
marks[2] = 89; //changing the value
cout<<marks[0]<<endl;
cout<<marks[1]<<endl;
cout<<marks[2]<<endl;
cout<<marks[3]<<endl;
cout<<endl;
//modifying the array with the help of for loop
for (int i = 0; i < 4; i++)
{
/* code */
cout<<"the value of marks is "<<marks[i]<<endl;
}
cout<<endl;
//challenge: do this using while or do while loops
//using pointers
int* p = marks;
cout<<"the value of *p is "<<*p<<endl;
cout<<"the value of *(p+1) is "<<*(p+1)<<endl;
cout<<"the value of *(p+2) is "<<*(p+2)<<endl;
cout<<"the value of *(p+3) is "<<*(p+3)<<endl;
cout<<endl;
cout<<*(p++)<<endl;
cout<<*++p<<endl;
return 0;
}