Review questions for COSC 341 Exam: C language 1. Consider this C program /* compute and output prefix sums */ #include void printArray(int a[], int size) { int i; for (i = 0; i < size; i++) { printf("%d ", a[i]); } printf("\n"); } int main() { int i; int a[] = {1, 2, 3, 4, 5}; int number = (sizeof a) / sizeof(int); int c[number]; c[0] = a[0]; for (i = 1; i < number; i++) { c[i] = c[i-1] + a[i]; } printf("prefix sum: "); printArray(c, number); return 0; } 1.a. What is the output? 1.b. Modify this code to do the following: Add an array b[] with values {10, 20, 30, 40, 50} Compute array c[] -- the values of each c element is the sum of corresponding values of a[] and b[] Output array c[] 1.c. Suppose you change the original code line int a[] = {1, 2, 3, 4, 5}; to int a[] = {1, 2, 3}; Will the resulting program still compute prefix sum? 1.d. You comment (explain) the line of code int number = (sizeof a) / sizeof(int); What is your comment? 2. Given the operator precedence/associativity (http://www.swansontec.com/sopc.html) fully parenthesize the following expressions to explicitly show the order of operations. Ignore type. Example: 3 + 2 + 5 * 6 * 7 --> (3 + 2) + ((5 * 6) * 7) y = x << 3 * x & 8 y = x = count + 7 ++i++ p -> next -> data x < 3 || y >>3 > 2 3. Consider this sequence of declarations and assignments in C int a, b, c int *p, *q, *r; int **s; a = 10; b = 20; p = &a; q = &b; r = p; c = *p * *q; *r = *q; s = &q; **s = 30; What are values of a, b, c?