CSCA48 Test #3
• You will have 30 minutes to answer 2 questions
• Please ensure that your hands, head, and desktop are visible in your
webcam
• Turn your camera, microphone, and speakers on, leave your volume at a low level
• Once the test has begun, you may not touch or approach your computer unless told to do so, you must remain in view of the camera at all times
• If you have a question, raise your hand and you will be moved to a breakout room where you can talk to an invigilator
• All answers must be legible and clearly labeled, no marks will be given for unclear or unreadable answers
• If any question is under-specified, you will not be penalized for making a reasonable assumption
Question 1
Draw 2 memory models, one when the execution of the code reaches the line //MM1, and one when it reaches //MM2
• Represent any unknown values by ?
• Represent any inaccessible memory by X
• Clearly label which memory model is which
char s[5];
strcpy(s,”CAT”);
char c = ‘B’;
char *cp = &c;
char *sp = &s[0];
//MM1
*(sp) = *(cp);
cp++;
*(cp) = *(sp + 1);
sp ++;
*(sp) = *(sp + 1);
//MM2
Question 2
Write a function to create a copy of an array of integers with any negative numbers removed, and a main function that provides an example of calling your function.
(e.g., main has an array with [7, -2, 5, -8] and needs a copy that just has [7, 5] without changing the original array).
• You can choose your own function name, parameters, return type, etc.
• Your function cannot modify the original array
• You can not use square brackets in your function (main can use
square brackets)
• You can not include any files