-1

shaded boxes are pointers and elements that hold the values are on the heap

diagram

I pretty much need to come up with the statements to implement the diagram. I am so thrown off by initializing something pointed to with 3 levels of indirection that is on the heap.

please help me... this is what i have

int *c{ new int(18) },
 ***a{ new int**(&c) },
 *e{ new int(22) },
 **b;
b = &e;

    b = nullptr;
e = nullptr;
a = nullptr;
c = nullptr;

delete b, e, a, c;
  • based on the diagram, `a` is not supposed to go via `c` – M.M Sep 01 '16 at 04:47
  • Maybe it will be easier to get your head around if you use a named variable for every box in your diagram, and stick to one initialization or assignment at a time – M.M Sep 01 '16 at 04:48
  • Note that the programming field is not at all like the restaurant business. More stars is not generally considered "better" in any way... – twalberg Sep 02 '16 at 19:23

1 Answers1

0

Figured it out.

Example for the pointer a.

int*** a;
a = new int**;
*a = new int*;
**a = new int(18);