CSCA48 Test #2
• 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
What is printed by the code below? • You may assume string.h has been included
• If any value cannot be determined, replace it with a ?
• If any line could cause the code to crash, replace the line with ERROR
char s[10];
strcpy(s, “ABCDEFG”);
s[0] = ‘\0’;
strcpy(s, “XYZ”);
s[1] = ‘\0’;
s[3] = ‘2’;
for(int i=0; i < 10; i++){
printf("s[%d] = %c\n", i, s[i]);
}
Question 2
Draw the memory model for the code below as it would appear after line 2 is executed for the first time
• You may choose any sensible values for memory addresses
• Indicate any undefined values by a ?
1| int my_func(int input[4]){
2| input[0] = 99;
3| return input[1];
4| }
5|
6| int main(){
7| int a[4];
8| a[0] = 7;
9| a[1] = 8;
10| a[2] = 9;
11| int r = my_func(a);
12| }