CIS1057 FALL 2010 MIDTERM 2 (Total points = 170) (5) 1. Describe what is a Compiler. (5) 2. What is a BIT? what is a BYTE? (5) 3. Give examples of Keywords and Identifiers (15) 4 Give an example of: (a) A compiler directive (b) A variable declaration (c) A Conditional Statement (d) A loop Statement (e) An I/O Statement (10) 5. You are given the following for loop: for(i=6; i > 0; i--) printf("i = %d\n",i); Rewrite it using a while loop. (5) 6. What is the value of the expression (show all steps) 2 < 3 && 3 == 3 || 3 < 1 (5) 7. What is printed out by the following program fragment, assuming that x,y, and z are integer variables, with x and y initialized to 0 and z initialized to 3: if(x>0) if(y>0) z=1; else z=2; printf("z=%d\n",z); (5) 8. Describe all that you know about the following function prototype: int moo (const char *a, int n); [of course you do not know what moo does, but you know what it is, what are its parameters..] (10) 9. What is written by the following program? #include int x = 2; int y = 3; int z = 4; void moo(int x, int *y){ int z = 7; x = x+3; *y = *y+3; z = z+3; printf("moo : x = %1d, y = %1d, z = %1d\n", x,y,z); } int main(void){ moo(x, &y); printf("main: x = %1d, y = %1d, z = %1d\n", x,y,z); } (10)10. What is written by the following program fragment: int a[10]; int lcv; for (lcv=0;lcv<10;lcv++) a[lcv] = lcv; for (lcv=0;lcv<5;lcv++) printf("%d %d\n", a[lcv], a[9 - lcv]); (10)11. What is the output of the following program fragment: printf("%d\n", 10%3); printf("%6.2f\n", 20/3); printf("%f\n", ((double)20)/3); printf("%f\n", (double)(20/3)); printf("%d\n", (int)3.1416); (5) 12. What is the Scope of an identifier? (10)13. What is a string? Give the definition, a declaration of a string variable, an example of a string literal. (5) 14. Assuming that the integer variable x has value 3, what is its value after each of the following statements: (a) x *= 5; (b) x = (x<2)?7:9; (c) x = x%2; (10)15. For a function, what are: (1) its formal parameters (2) actual parameters (3) rules for correspondence of formal and actual parameters. Show an example to clarify your answers. (10)16. Describe in English the Linear Search Algorithm, give its function prototype for integer values, and indicate its complexity in terms of the number n of given values. (15)17. Implement the function void moo(int n, char *a[n]) that prints out, one per line, all the strings in a. (15)18. Implement the function void reverse(int n, int a[n]) that reverses the content of the array a. (15)19. Implement the function double average(int m, int n, int a[m][n]) which returns the average of the values in the mxn matrix a.