{ "q1": { "type": "blank", "question": "\n\n\nGiven the following C code:\n\n\n\n
\nchar C = '0';\n\nint main(int argc, char *argv[]) {\n    int    i      = 1;\n    double d      = 2.0;\n    int    ia[10] = {0};\n    int   *ip     = ia;\n    return 0;\n}\n
\n\n

How many bytes are allocated for the following\nvariables?

\n\n
    \n
  1. C: ____
  2. \n
  3. i: ____
  4. \n
  5. d: ____
  6. \n
  7. ia: ____
  8. \n
  9. ip: ____
  10. \n
\n" }, "q2": { "type": "multiple", "question": "\n\nGive the C code above in Q1, which of the following\nstatements are true (select all that apply)?\n\n", "responses": { "c_stack": "C is allocated in the stack region of memory.", "c_heap": "C is allocated in the heap region of memory.", "c_data": "C is allocated in the data region of memory.", "c_code": "C is allocated in the code region of memory.", "d_stack": "d is allocated in the stack region of memory.", "d_heap": "d is allocated in the heap region of memory.", "d_data": "d is allocated in the data region of memory.", "d_code": "d is allocated in the code region of memory.", "ip_stack": "ip is allocated in the stack region of memory.", "ip_heap": "ip is allocated in the heap region of memory.", "ip_data": "ip is allocated in the data region of memory.", "ip_code": "ip is allocated in the code region of memory." } }, "q3": { "type": "blank", "question": "\n

A pointer is a type of variable that holds the\nlocation or ____ of data stored in memory.

\n\n

To get the location of a variable, we can use the ____\nprefix operator.

\n\n

To get the value referenced by a pointer, we can use the\n____ prefix operator.

\n" }, "q4": { "type": "multiple", "question": "\n\nWhich of the following statements regarding arrays in C is true\n(select all that apply)?\n\n", "responses": { "array_fixed": "Arrays are fixed sized blocks of contiguous memory.", "array_locality": "Arrays typically exhibit good spatial locality.", "array_random": "Arrays provide efficient random access.", "array_front": "Arrays provide efficient insertion into the front of the sequence.", "array_middle": "Arrays provide efficient deletion from the middle of the sequence.", "array_labels": "Array names are labels to the first element in the array.", "array_index": "The Array index operation a[i] is equivalent to *(a + i)." } }, "q5": { "type": "order", "question": "\n

Given the following C code, shout.c

\n\n
\nchar *str_shout(const char *s) {\n    return shout;\n        *c = toupper(*c);\n    char *shout = strdup(s);\n    for (char *c = shout; *c; c++)\n}\n\nint main(int argc, char *argv[]) {\n        char *shout = str_shout(buffer);\n        fputs(shout, stdout);\n    while (fgets(buffer, BUFSIZ, stdin)) {\n    char buffer[BUFSIZ];\n        free(shout);\n    }\n}\n
\n\n

The code is suppose to read one line of input from\nstdin, use str_shout to convert all the letters in\nthe line to uppercase, and then print out the new string. Unfortunately,\nthe lines of code are scrambled.

\n\n

Unscramble the following lines of code to implement the\nstr_shout function:

\n", "responses": { "a": "return shout;", "b": " *c = toupper(*c);", "c": "char *shout = strdup(s);", "d": "for (char *c = shout; *c; c++)" } }, "q6": { "type": "order", "question": "\n

Given the C code above in Q5, shout.c,\nunscramble the following lines of code to implement the\nmain function:

\n", "responses": { "a": " char *shout = str_shout(buffer)", "b": " fputs(shout, stdout);", "c": "while (fgets(buffer, BUFSIZ, stdin)) {", "d": "char buffer[BUFSIZ];", "e": " free(shout);", "f": "}" } }, "q7": { "type": "multiple", "question": "\n

Given the following C code involving structs, which of\nthe following statements are true (select all that apply)?

\n\n
\ntypedef struct {\n    char   *first_name;\n    char   *last_name;\n    uint8_t age;\n} Person;\n\nint main(int argc, char *argv[]) {\n    Person  d = {\"Darren\", \"Ballad\", 29};\n    Person *p = &d;\n\n    ...\n\n    return 0;\n}\n
\n", "responses": { "size_d_19": "sizeof(Person) is 19.", "size_d_24": "sizeof(Person) is 24.", "max_age_128": "The maximum age a Person can be is 128.", "max_age_255": "The maximum age a Person can be is 255.", "d_first_name_d": "To access d's first_name we would do d.first_name.", "d_first_name_p": "To access d's first_name we would do d->first_name.", "p_last_name_d": "To access p's last_name we would do p.last_name.", "p_last_name_p": "To access p's last_name we would do p->last_name." } } }