Skip to content

Commit 5b7614e

Browse files
Arrays
1 parent 3f22991 commit 5b7614e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

01 - Arrays/Arrays_and_Functions.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
// We can also pass the array as pointer like "int *arr"
6+
7+
void printArray(int arr[], int size) {
8+
for (int i = 0; i < size; i++) {
9+
arr[i] = arr[i] * 2; // Updating the array
10+
cout << arr[i] << " ";
11+
}
12+
}
13+
14+
int main() {
15+
16+
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
17+
18+
int size = sizeof(arr) / sizeof(int);
19+
20+
cout << "Size of array: " << sizeof(arr) << endl;
21+
22+
cout << "Inside Main the array is : ";
23+
24+
for (int i = 0; i < size; i++) {
25+
cout << arr[i] << " ";
26+
}
27+
28+
cout << endl << "Inside Function the array is : ";
29+
30+
printArray(arr, size);
31+
32+
return 0;
33+
}

0 commit comments

Comments
 (0)