{ "q1": { "type": "single", "question": "\n
Inside the read_numbers function of sum.c, there is an\nerror on the following line of code:
\n\n\nwhile (i < n && scanf(\"%d\", numbers[i]) != EOF)\n\n\n
Which of the following options fixes the problem with this line of\ncode?
\n", "responses": { "0": "while (i <= n && scanf(\"%d\", numbers[i]) != EOF)", "1": "while (i < n && scanf(\"%d\", numbers[i]) == EOF)", "2": "while (i < n || scanf(\"%d\", numbers[i]) != EOF)", "3": "while (i < n && scanf(\"%d\", (int *)numbers[i] != EOF)", "4": "while (i < n && scanf(\"%d\", &numbers[i]) != EOF)", "5": "while (i < n && scanf(\"%d\", *numbers[i]) != EOF)" } }, "q3": { "type": "single", "question": "\nInside the main function of sum.c, there is an error\non the following line of code:
\n\n\nprintf(\"{}\\n\", total);\n\n\n
Which of the following options fixes the problem with this line of\n", "responses": { "0": "printf(total + \"\\n\");", "1": "printf(\"{}\\n\", &total);", "2": "printf(\"{}\\n\", (char *)total);", "3": "printf(\"%d\\n\", total);", "4": "printf(\"%s\\n\", total);", "5": "printf(\"%s\\n\", (char *)total);" } }, "q2": { "type": "single", "question": "\n
The sum_numbers function in sum.c contains a common\nerror regarding arrays and pointers. Which of the following\noptions explains this error and fixes it?
\n", "responses": { "0": "You can't pass a statically allocated array to a function; dynamically allocate it first using malloc.", "1": "You can't declare an array argument using int numbers[]; instead you should declare it as int *numbers.", "2": "To use sizeof on an array, you must deference it first; so do sizeof(*numbers).", "3": "To use sizeof on an array, you must deference it first; so do sizeof(&numbers).", "4": "You shouldn't use sizeof to get the size of an array; use array.size() instead.", "5": "You shouldn't use sizeof to get the size of an array; pass the size of the array in as an additional argument." } }, "q5": { "type": "order", "question": "\nFill in the blanks for cat.c by ordering the following\nfunctions:
\n", "responses": { "fclose": "fclose", "strerror": "strerror", "fputs": "fputs", "exit": "exit", "fgets": "fgets", "fprintf": "fprintf", "fopen": "fopen", "strlen": "strlen", "strcmp": "strcmp" } }, "q4": { "type": "single", "question": "\nAfter fixing the errors above in sum.c, suppose we modify the\nMAX_NUMBERS constant to be the value 1<<30. Which of the\nfollowing most accurately explains what is displayed when we run the\nprogram with seq 1 10 | ./sum?
\n", "responses": { "0": "55, which is the sum of 1 - 10", "1": "Nothing is printed because no command line arguments are passed the the program.", "2": "Segmentation fault because we didn't read the input from the pipe.", "3": "Segmentation fault because the computer does not have enough memory.", "4": "Segmentation fault because our array is declared on the heap and is too big.", "5": "Segmentation fault because our array is declared on the stack and is too big." } } }