-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpointerFunction.cpp
More file actions
38 lines (27 loc) · 804 Bytes
/
pointerFunction.cpp
File metadata and controls
38 lines (27 loc) · 804 Bytes
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
//preprocessor instructions
#include <iostream>
//function prototypes
void writeOutput(int*);
void computeTriple(int*);
int main() {
int num = 5;
//initialize pointer with address of num
int* ptr = #
//pass pointer to writeOutput function
writeOutput(ptr);
//use pointer to increase the variable value(num)
*ptr += 15;
writeOutput(ptr);
computeTriple(ptr);
writeOutput(ptr);
return 0;
}
/*FUNCTIONS THAT OPERATE DIRECTLY ON VARIABLES WITHIN THE CALLING FUNCTION DO NOT NEED A RETURN STATEMENT*/
//function outputs the current value of the pointer
void writeOutput(int* value) {
std::cout << "Current value: " << *value << std::endl;
}
//function multiplies the value of the pointer by 3
void computeTriple(int* value) {
*value *= 3;
}