-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathptr_ptr.cpp
51 lines (39 loc) · 926 Bytes
/
ptr_ptr.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
#include "faasm/faasm.h"
#include <stdio.h>
class MyClass
{
public:
explicit MyClass(int newInt) { myInt = newInt; }
int myInt = 0;
};
void setMyClassPointer(MyClass** ptrPtr, int newInt)
{
MyClass* newPtr;
newPtr = new MyClass(newInt);
if (ptrPtr == NULL) {
printf("Pointer to pointer is null A\n");
}
*ptrPtr = newPtr;
if (ptrPtr == NULL) {
printf("Pointer to pointer is null B\n");
}
}
int main(int argc, char* argv[])
{
// Create a pointer and a pointer to a pointer
MyClass* aPtr;
MyClass** aPtrPtr = &aPtr;
setMyClassPointer(aPtrPtr, 2);
if (aPtr == NULL) {
printf("Pointer pointer causes null\n");
return 1;
}
if (aPtrPtr == NULL) {
printf("Pointer to pointer is null\n");
}
if (aPtr->myInt == 2) {
printf("Pointer pointer handled properly\n");
return 0;
}
return 1;
}