{ "q1": { "type": "blank", "question": "\n
Suppose you had the following source files:
\n\nComplete the following Makefile that builds a shared\nlibrary (ie. liblist.so) and then builds a dynamic\nexecutable (ie. program) that links against the shared\nlibrary:
\n\n\nCC= gcc\nCFLAGS= -Wall -g -std=gnu99 -fPIC\nLD= gcc\nLDFLAGS= -L.\n\nprogram: ____ // 1.\n ____ // 2.\n\nliblist.so: ____ // 3.\n ____ // 4.\n\nlist.o: ____ // 5.\n ____ // 6.\n\nmain.o: ____ // 7.\n ____ // 8.\n\n\n\n
Be sure to use the appropriate variables.
\n" }, "q2": { "type": "multiple", "question": "\nGiven the following [C] code:
\n\n\nint main(int argc, char *argv[]) { // | Label | Address | Value |\n int n = 16; // | | 0xF | 0x00 |\n int a[] = {n}; // | n | 0xE | 0x10 |\n int *p = a; // | | 0xD | |\n return 0; // | | 0xC | |\n} // | | 0xB | |\n // | | 0xA | |\n\n\n
Assuming a 16-bit little endian machine where each integer is\n2 bytes, each character is 1 byte, and each pointer is\n2 bytes, fill in the stack frame to the right by recording\nthe location of the variables above and their values at the appropriate\naddresses. Afterwards, which of the following expressions are true\n(select all that apply)?
\n", "responses": { "a": "a == 0xB", "b": "a == 0xC", "c": "&p == 0xB", "d": "&p == 0xA", "e": "*p == n", "f": "*p == a", "g": "*p == a[1]", "h": "&n == &a[0]" } }, "q3": { "type": "blank", "question": "\nGiven the following [C] code:
\n\n\ntypedef struct {\n char key;\n int value;\n} Pair;\n\nint main(int argc, char* argv[]) {\n char c = 'k';\n int v = 2;\n\n Pair p0 = {c, v};\n Pair *p1 = malloc(sizeof(Pair));\n Pair *p2 = calloc(v, sizeof(Pair));\n Pair **p3 = calloc(v, sizeof(Pair *));\n return 0;\n}\n\n\n
Fill in the table below to identify how\nmuch memory (in bytes) is allocated in each memory segment (ie.\ndata, heap, stack) for the corresponding variable\ndeclaration:
\n\nCode | \nData | \nHeap | \nStack | \n \n \n\n
---|---|---|---|
char c = 'k'; | \n____ (01) | \n____ (02) | \n____ (03) | \n
int v = 2; | \n____ (04) | \n____ (05) | \n____ (06) | \n
Pair p0 = {c, v}; | \n____ (07) | \n____ (08) | \n____ (09) | \n
Pair *p1 = malloc(sizeof(Pair)); | \n____ (10) | \n____ (11) | \n____ (12) | \n
Pair *p2 = calloc(v, sizeof(Pair)); | \n____ (13) | \n____ (14) | \n____ (15) | \n
Pair *p3 = calloc(v, sizeof(Pair *)); | \n____ (16) | \n____ (17) | \n____ (18) | \n
Assume this program is compiled on a 64-bit Linux machine (ie.\nthe student machines).
\n" }, "q4": { "type": "blank", "question": "\nGiven the doubly linked list in Homework\n07, implement a list_contains function that returns whether or\nnot a given Value is found in the List:
\n\n\n/**\n * Returns whether or not list contains the value.\n **/\nbool list_contains(List *l, Value v) {\n Node *curr = ____; // 1. ????\n\n while (____) { // 2. ????\n if (____) { // 3. ????\n return _____; // 4. ????\n }\n curr = ____; // 5. ????\n }\n\n return ____; // 6. ????\n}\n\n" }, "q5": { "type": "blank", "question": "\n
Given the following array and bitset, complete the code\nto add each element in the array to the bitset:
\n\n\nint numbers[] = {1, 12, 7, 10, -1};\nint32_t bitset = 0;\n\nfor (int *n = numbers; *n >= 0; n++) {\n bitset = ____; // 1. ????\n}\n\n\n