adding the programs
This commit is contained in:
@@ -9,18 +9,11 @@
|
|||||||
|
|
||||||
- Following the conventions used in Data Structures lecture for memory diagramming, draw a picture of the stack and the heap that result from executing the statements below. Use a ‘?’ to represent uninitialized values.
|
- Following the conventions used in Data Structures lecture for memory diagramming, draw a picture of the stack and the heap that result from executing the statements below. Use a ‘?’ to represent uninitialized values.
|
||||||
|
|
||||||
```cpp
|
[Program 1](fruits.cpp)
|
||||||
char*** carrot;
|
[Program 2](grains.cpp)
|
||||||
char** broccoli;
|
[Program 3](desserts.cpp)
|
||||||
char* tomato;
|
[Program 4](veggies.cpp)
|
||||||
char radish = 'q';
|
[Program 5](protein.cpp)
|
||||||
tomato = new char;
|
|
||||||
*tomato = 'z';
|
|
||||||
broccoli = new char*;
|
|
||||||
*broccoli = tomato;
|
|
||||||
carrot = new char**;
|
|
||||||
*carrot = broccoli;
|
|
||||||
```
|
|
||||||
|
|
||||||
Show your diagram to your teammate, and ask the teammate to reverse engineer code for your diagram; at the same time, you reverse engineer code for your teammate's diagram.
|
Show your diagram to your teammate, and ask the teammate to reverse engineer code for your diagram; at the same time, you reverse engineer code for your teammate's diagram.
|
||||||
|
|
||||||
|
|||||||
10
labs/04_memory_debugging/dessert.cpp
Normal file
10
labs/04_memory_debugging/dessert.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
bool** cake;
|
||||||
|
bool pie;
|
||||||
|
bool fudge;
|
||||||
|
pie = true;
|
||||||
|
cake = new bool*[5];
|
||||||
|
cake[1] = &pie;
|
||||||
|
bool* donut = new bool;
|
||||||
|
*donut = false;
|
||||||
|
cake[2] = donut;
|
||||||
|
cake[4] = &fudge;
|
||||||
10
labs/04_memory_debugging/fruits.cpp
Normal file
10
labs/04_memory_debugging/fruits.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
int pear = 3;
|
||||||
|
int* apple;
|
||||||
|
int banana[pear];
|
||||||
|
int* orange;
|
||||||
|
apple = new int[pear];
|
||||||
|
orange = &banana[1];
|
||||||
|
apple[0] = 6;
|
||||||
|
apple[1] = 7;
|
||||||
|
apple[2] = 8;
|
||||||
|
*orange = 5;
|
||||||
10
labs/04_memory_debugging/grains.cpp
Normal file
10
labs/04_memory_debugging/grains.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
float* oat[3];
|
||||||
|
oat[1] = new float;
|
||||||
|
*oat[1] = 3.14;
|
||||||
|
oat[2] = new float;
|
||||||
|
*oat[2] = 6.02;
|
||||||
|
float rice;
|
||||||
|
float* wheat;
|
||||||
|
wheat = oat[2];
|
||||||
|
float** barley = new float*;
|
||||||
|
*barley = oat[1];
|
||||||
11
labs/04_memory_debugging/protein.cpp
Normal file
11
labs/04_memory_debugging/protein.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
int tofu = 3;
|
||||||
|
int chicken = 2;
|
||||||
|
double** fish = new double*[tofu];
|
||||||
|
for (int beef = 0; beef < tofu; beef++) {
|
||||||
|
fish[beef] = new double[chicken];
|
||||||
|
}
|
||||||
|
fish[0][0] = 1.41421;
|
||||||
|
fish[0][1] = 1.61803;
|
||||||
|
fish[1][0] = 2.71828;
|
||||||
|
fish[1][1] = 3.14159;
|
||||||
|
fish[2][0] = 6.02214;
|
||||||
10
labs/04_memory_debugging/veggies.cpp
Normal file
10
labs/04_memory_debugging/veggies.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
char*** carrot;
|
||||||
|
char** broccoli;
|
||||||
|
char* tomato;
|
||||||
|
char radish = 'q';
|
||||||
|
tomato = new char;
|
||||||
|
*tomato = 'z';
|
||||||
|
broccoli = new char*;
|
||||||
|
*broccoli = tomato;
|
||||||
|
carrot = new char**;
|
||||||
|
*carrot = broccoli;
|
||||||
Reference in New Issue
Block a user