Exercises for the student
The following exercises are representative of questions found on the exam.
- Given the following declarations and code, answer these question
- What type of variable is dog?
- What type of variable is cat? (no, not "arrayPtr").
- Draw the picture of memory that results from this code
typedef int* intPtrArray[ 3 ];
typedef intPtrArray* arrayPtr;
arrayPtr cat;
int *dog;
dog = new int;
*dog = 42;
cat = new intPtrArray;
cat[ 0 ] = dog;
cat[ 1 ] = 0;
cat[ 2 ] = new int;
*(cat[ 2 ]) = 17;
- Draw the picture of memory that results from the following code
char *fischer;
fischer = new char[ 3 ];
fischer[ 0 ] = 'p';
fischer[ 1 ] = 'k';
fischer[ 2 ] = '4';
- Draw the picture of memory that results from the following code
struct soprano
{
int x;
char ch[ 3 ];
}
typedef soprano* alto[5];
soprano *jane;
alto *joe;
jane = new soprano;
jane->x = 1;
jane->ch[ jane->x ] = 'g';
joe = new alto;
joe[ 0 ] = new soprano;
joe[ 0 ]->ch[ 2 ] = 'q';
joe[ 3 ] = jane;
Last Modified: Monday, 28-Aug-2006 10:16:04 EDT