The superhero struct wonderwoman int isis superhero superman

  • Slides: 44
Download presentation
The superhero struct wonderwoman (int) isis (superhero *) superman (int *[]) I use short

The superhero struct wonderwoman (int) isis (superhero *) superman (int *[]) I use short internal arrows to remind myself which elements are uninitialized pointers. If a pointer is set to null, you should represent it with a line through the box, like so:

superhero marineboy[2];

superhero marineboy[2];

superhero marineboy[2]; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy

superhero marineboy[2]; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy

superhero *ironman; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy

superhero *ironman; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy

superhero *ironman; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

superhero *ironman; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman = &marineboy[1]; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman = &marineboy[1]; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman = &marineboy[1]; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman = &marineboy[1]; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. wonderwoman = 152; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. wonderwoman = 152; wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. wonderwoman = 152; 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy

marineboy[0]. wonderwoman = 152; 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. superman[0] = new int[2]; 152 wonderwoman (int) isis (superhero *) superman (int *[])

marineboy[0]. superman[0] = new int[2]; 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. superman[0] = new int[2]; heap stack 152 wonderwoman (int) isis (superhero *) superman

marineboy[0]. superman[0] = new int[2]; heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int

marineboy[0]. superman[1] = &(ironman->wonderwoman); heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman->superman[0] = marineboy[0]. superman[1]; heap stack 152 wonderwoman (int) isis (superhero *) superman (int

ironman->superman[0] = marineboy[0]. superman[1]; heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman->superman[0] = marineboy[0]. superman[1]; heap stack 152 wonderwoman (int) isis (superhero *) superman (int

ironman->superman[0] = marineboy[0]. superman[1]; heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman->superman[1] = &(marineboy[0]. superman[0][1]; heap stack 152 wonderwoman (int) isis (superhero *) superman (int

ironman->superman[1] = &(marineboy[0]. superman[0][1]; heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

ironman->superman[1] = &(marineboy[0]. superman[0][1]); heap stack 152 wonderwoman (int) isis (superhero *) superman (int

ironman->superman[1] = &(marineboy[0]. superman[0][1]); heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

*(ironman->superman[1]) = 9189; heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[])

*(ironman->superman[1]) = 9189; heap stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

*(ironman->superman[1]) = 9189; heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int

*(ironman->superman[1]) = 9189; heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero

marineboy[1]. isis = ironman->isis = ironman; heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

State before Barberella: heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int

State before Barberella: heap stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman

In Barbarella: heap elektra() stack 152 wonderwoman (int) isis (superhero *) superman (int *[])

In Barbarella: heap elektra() stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack We don’t have direct access to electra() local variables anymore. At least not by those names! 9189

barbarella(marineboy[1], ironman->isis); heap elektra() stack 9189 152 wonderwoman (int) isis (superhero *) superman (int

barbarella(marineboy[1], ironman->isis); heap elektra() stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack These arguments are passed into barbarella, and received on the other side as….

barbarella(superhero& storm, superhero *& catwoman) heap elektra() stack 9189 152 wonderwoman (int) isis (superhero

barbarella(superhero& storm, superhero *& catwoman) heap elektra() stack 9189 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy These arguments are passed into barbarella, and received on the other side as…. ironman References! barbarella() stack storm Careful here, catwoman is a REFERENCE to a POINTER, to a superhero catwoman

storm. wonderwoman = 465; heap elektra() stack 152 wonderwoman (int) isis (superhero *) superman

storm. wonderwoman = 465; heap elektra() stack 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

storm. wonderwoman = 465; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *)

storm. wonderwoman = 465; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->isis = &storm; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *) superman

catwoman->isis = &storm; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->isis = &storm; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *) superman

catwoman->isis = &storm; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy No change! catwoman->isis is the same as catwoman, which is already pointing at the address of the object that storm references. ironman barbarella() stack storm 9189 catwoman

catwoman->wonderwoman = 830; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *) superman

catwoman->wonderwoman = 830; heap elektra() stack 465 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->wonderwoman = 830; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman

catwoman->wonderwoman = 830; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->isis[0]. superman[1] = &(storm. isis->wonderwoman); heap elektra() stack 830 152 wonderwoman (int) isis (superhero

catwoman->isis[0]. superman[1] = &(storm. isis->wonderwoman); heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->isis[0]. superman[1] = &(storm. isis->wonderwoman); heap elektra() stack 830 152 wonderwoman (int) isis (superhero

catwoman->isis[0]. superman[1] = &(storm. isis->wonderwoman); heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm 9189 Remember: isis[0] is the same as *isis. Fun fact: isis[-1] is the same as marineboy[0]! That’s because isis[-1] is the same as *(isis + (-1 * size. Of. Superhero)), or “dereference the address 1 superhero behind isis” catwoman

catwoman = &storm; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman

catwoman = &storm; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman = &storm; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman

catwoman = &storm; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy Another no change operation! ironman barbarella() stack storm catwoman 9189

catwoman->wonderwoman = 507; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman

catwoman->wonderwoman = 507; heap elektra() stack 830 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->wonderwoman = 507; heap elektra() stack 507 152 wonderwoman (int) isis (superhero *) superman

catwoman->wonderwoman = 507; heap elektra() stack 507 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->isis = new superhero[2]; heap elektra() stack 507 152 wonderwoman (int) isis (superhero *)

catwoman->isis = new superhero[2]; heap elektra() stack 507 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

catwoman->isis = new superhero[2]; heap elektra() stack 507 152 wonderwoman (int) isis (superhero *)

catwoman->isis = new superhero[2]; heap elektra() stack 507 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189

State before barbarella exits: heap elektra() stack 507 152 wonderwoman (int) isis (superhero *)

State before barbarella exits: heap elektra() stack 507 152 wonderwoman (int) isis (superhero *) superman (int *[]) marineboy ironman barbarella() stack storm catwoman 9189