-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathexercise.hpp
45 lines (38 loc) · 1.07 KB
/
exercise.hpp
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
// Exercise 1
// -- Add a member variable named p of type pointer-to-int to this struct
// -- Ensure that p has an appropriate default value
struct example1 {
};
// Exercise 2
// -- Modify this function to return the value of the int that p points to
inline int return_value(int* p)
{
return 0;
}
// Exercise 3
// Here you are given a reference to an int, i
// -- Modify this function to return the *address* of i
inline int* return_address(int& i)
{
return nullptr;
}
// Exercise 4
// -- Modify this function so that it sets the value of p's target to 12
inline void set_to_twelve(int* p)
{
}
// Exercise 5
// -- Modify this function so that it checks whether p is a valid pointer,
// and if so, set its target to 12
// Be careful, the test may crash if you get this wrong!
inline void maybe_set_to_twelve(int* p)
{
}
// Exercise 6
// Now things are getting tricky!
// -- what are the types of p1 and p2 here?
// -- implement this function so that it swaps the pointers p1 and p2
// (NOT their target values!)
inline void ptr_swap(int*& p1, int*& p2)
{
}