Homework 32
Examine the following source code and fill in the matrix below:
#include <iostream>
using namespace std;
struct myStruct
{
double x, y;
int* ptr;
};
int main()
{
myStruct* bunchOfStructs;
myStruct singleStruct;
int variable1, variable2;
double variable3;
char variable4;
bunchOfStructs = new myStruct[3];
singleStruct.x = 3.6;
singleStruct.y = 12.7;
singleStruct.ptr = new int[5];
for(int i = 0; i < 5; i++)
singleStruct.ptr[i] = i * 4;
for(i = 0; i < 3; i++)
{
bunchOfStructs[i].x = i / 2;
bunchOfStructs[i].y = (i / 2) * -1;
bunchOfStructs[i].ptr = new int[5];
for(int j = 0; j < 5; i++)
bunchOfStructs[i].ptr[j] =
(i + j) * 3;
}
return 0;
}
1)
If the value of a variable is an address, simply write ADDR
2)
If the variable is a struct , simply write STRUCT
Hint: Do this by hand, not by running in Visual Studio. You don't need to run/simulate the whole program above to be able to fill out the
matrix, just look at the variable and figure out what its value would be.
Once a variable is
initialized its value is not modified.
| Variable Name | Type | Value |
| singleStruct | ||
| bunchOfStructs | ||
| singleStruct.x | ||
| singleStruct.ptr | ||
| bunchOfStructs[1].y | ||
| bunchOfStructs[1].ptr | ||
| bunchOfStructs[1].ptr[3] | ||
| bunchOfStructs[1].ptr[5] |
|
|
| bunchOfStructs[1] |