-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10array.cpp
More file actions
42 lines (36 loc) · 1.06 KB
/
Copy path10array.cpp
File metadata and controls
42 lines (36 loc) · 1.06 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
#include<iostream>
using namespace std;
int main(){
//Array : storing same datatypes in a block manner
//there are two ways of storing arrays
//first method
int marks[] = {34, 44, 67, 78};
cout<<marks[0]<<endl;
cout<<marks[1]<<endl;
cout<<marks[2]<<endl;
cout<<marks[3]<<endl;
//second method
int Mathmarks[4];
Mathmarks[0]=23;
Mathmarks[1]=232;
Mathmarks[2]=231;
Mathmarks[3]=236;
cout<<Mathmarks[0]<<endl;
cout<<Mathmarks[1]<<endl;
cout<<Mathmarks[2]<<endl;
cout<<Mathmarks[3]<<endl;
//a fast way to print all the values of array
for (int i = 0; i < 4; i++)
{
cout<<"The value of marks "<<i<<" is "<<marks[i]<<endl;
}
//pointers and arrays
//address of an array doesn't need &
int *p = marks;
cout<<"The address of marks is "<<p<<endl;
cout<<"The value of marks[0] is "<<*p<<endl;
cout<<"The value of marks[1] is "<<*(p+1)<<endl;
cout<<"The value of marks[2] is "<<*(p+2)<<endl;
cout<<"The value of marks[3] is "<<*(p+3)<<endl;
return 0;
}