forked from tridibsamanta/CPP_Beginner_to_Expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP027_Functions_and_Pointers.cpp
55 lines (41 loc) · 1.06 KB
/
CPP027_Functions_and_Pointers.cpp
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
50
51
52
53
54
55
/**
* Author: Tridib Samanta
* Created: 17.01.2020
**/
#include <iostream>
using namespace std;
void multiplyBy(int *, int);
void multiplyArrayBy(int *, int, int);
int main()
{
int a = 10;
multiplyBy(&a, 5);
cout << a << endl;
cout << endl;
int array[10];
cout << sizeof(array) / sizeof(array[0]) << endl;
for (int i = 0; i < sizeof(array) / sizeof(array[0]); i++)
{
array[i] = i;
cout << "array [" << i << "] = " << array[i] << endl;
}
multiplyArrayBy(array, 5, sizeof(array) / sizeof(array[0])); // array = &array[0]
for (int i = 0; i < sizeof(array) / sizeof(array[0]); i++)
{
cout << "array [" << i << "] = " << array[i] << endl;
}
return 0;
}
void multiplyBy(int *var, int amount)
{
*var = *var * amount;
}
void multiplyArrayBy(int *array, int amount, int sizeOfArray)
{
while (sizeOfArray--)
array[sizeOfArray] *= amount;
/*
for(int i=0;i<sizeOfArray;i++) {
array[i] *= amount;
} */
}