Pop QuizQuestion 1Question 2Question 3Question 4Question 5Copyright ©: Nahrstedt, Angrave, Abdelzaher1Pop Quiz5 multiple choice questions (75 seconds each)Please mark only ONE answer per questionIf more than one answer are partially correct, choose the single BEST answerAnswer in the bubble-sheet (get pen/pencil ready now)Slide show formatCopyright ©: Nahrstedt, Angrave, Abdelzaher2Question 1 Q1) Which of the following code snippets is/are wrong?Case 1 Case 2 Case 3int *p; char a[2]; int b[10];*p=10; strcpy (a, “Hi”); *b=11;a) Case 1.b) Case 2c) Case 3d) Both Case 1 and Case 2e) Both Case 1 and Case 3Wrong:Dereferencing uninitialized pointerWrong:No room for NULL characterHalf CreditCopyright ©: Nahrstedt, Angrave, Abdelzaher3Question 2Q2) Given what you know about memory caches, which of the following content is best to remove to make room for new content that arrives to a full cache? a) Remove randomly selected contentb) Remove the oldest content (i.e., content that resided in the cache for the longest amount of time)c) Remove the newest content (i.e., content that resided in the cache for the shortest amount of time) d) Remove the most recently requested contente) Remove least recently requested content Think what Blockbuster might dowhen it’s time to rotate the shelvesRandom?? Clearly a bad idea!Bad! Will remove the classics and other “oldies but goodies”That’s crazy! Will remove the new releases!Best thing to do! If it’s been ages since anyonerented the movie, it’s time to take it off the shelves.Copyright ©: Nahrstedt, Angrave, Abdelzaher4Question 3Q3) Which of the following lines is/are wrong, if any: Line 1: char s[10];Line 2: strcpy (s, “Hi”);Line 3: strcat (“John: ”, s);Line 4: strcat (s, “, there!!”);a) Line 2b) Line 3c) Line 4d) Lines 3 and 4e) All is correct. Wrong. Concatenating to a constant.Wrong.“Hi, there!!” exceeds array size.CorrectI will consider this correct if you did not realize that the four lines are the same program.Half creditCopyright ©: Nahrstedt, Angrave, Abdelzaher5Question 4Q3) Which of the following lines is/are wrong, if any: Line 1: int **p, *q;Line 2: p=&q;Line 3: q = (int*) malloc (10*sizeof(int));Line 4: **p = 10;a) Line 1b) Line 2c) Line 3d) Lines 4e) All is correct. Writes 10 in the location pointed to by thepointer pointed to by p. Since p points to qand q points to a location that has been properly allocated via malloc, all is well.Copyright ©: Nahrstedt, Angrave, Abdelzaher6Question 5Q1: What is wrong with the code snippet below:int* p, x, y=10;p= &y;while (y>0) {x=y--;printf (“x= %d”, x);y=x; }*p = x;a) Pointer treated as an integer b) Infinite loopc) Dereferencing an invalid pointerd) y is a constant but treated as a variablee) Both (a) and (d)Assigns y to x before decrementing y. Restores the old (undecremented) y. Hence the loop never changes
View Full Document