-
Notifications
You must be signed in to change notification settings - Fork 0
/
funWithPointers.cpp
52 lines (38 loc) · 932 Bytes
/
funWithPointers.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
#include <cstdio>
#include "basicFunctions.h"
/*
void multiplyByTwo(double *passedVal){
*passedVal*=2;
}
void divideByTwo(double *passedVal){
*passedVal/=2;
}
*/
int main(int argc, char **argv){
double *aPointer;
double myValue, myModifiedValue;
myValue=5.75;
aPointer=&myValue;
*aPointer=7;
printf("\nCurrent Value: %lf", myValue);
myModifiedValue=10;
*aPointer=myModifiedValue;
printf("\nModified Value: %lf\n", myValue);
//Modify again in a function
//Try just passing pointers
multiplyByTwo(aPointer);
printf("Value multipled by two after fun: %lf\n", myValue);
divideByTwo(aPointer);
printf("Value divided by two after fun: %lf\n", myValue);
return 0;
}
/*
void multiplyByTwo(double *passedVal){
*passedVal*=2; //The value at this address is being
//multiplied by two
}
void divideByTwo(double *passedVal){
*passedVal/=2; //The value at this address is being
//divided by two
}
*/