{ "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)" } }, "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." } }, "q3": { "type": "single", "question": "\n

Inside 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);" } }, "q4": { "type": "single", "question": "\n

After 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." } }, "q5": { "type": "order", "question": "\n

Fill in the blanks for cat.c by ordering the following\nfunctions:

\n", "responses": { "fprintf": "fprintf", "argv": "argv[0]", "fputs": "fputs", "strlen": "strlen", "fgets": "fgets", "exit": "exit" } }, "q6": { "type": "blank", "question": "\n

In sum.c and cat.c, we read the input from\nstdin. If we wanted to read data from a file on the file system,\nwe would first need to call ____ to get a file handle or stream. We can\nthen use the same functions we used to read stdin and write to\nstdout (or even stderr) on the newly created file handle.\nOnce we are all done with the stream, we need to call ____.\n" }, "q7": { "type": "blank", "question": "\n

Instead of using a switch statement to check command line\narguments (as shown in cat.c), we can use a series of if,\nelse if statements:

\n\n
`\nwhile (argind < argc && strlen(argv[argind]) > 1 && argv[argind][0] == '-') {\n    char *arg = argv[argind++];\n    if (____(arg, \"-h\") == ____) {\n        usage(0);\n    } else {\n        usage(1);\n    }\n}\n`
\n" } }