COMP1604 COMPUTER SCIENCE, SUMMER EXAMINATIONS 2004 SOLUTIONS 1.(a) True (b) False (programmer can find out but not decide which memory location is used - the computer decides this) (c) True (d) value of w is 6 (e) no match (f) condition is true (g) i is 10 i is 1 i is 0 (h) j is 3 j is 2 j is 1 (i) False (j) correct answer is (j-3) fn() takes 1 argument of type pointer-to-int and does not return a value. (k) result is 50 (l) correct answer is (l-1) arr[0]*arr[2] (m) True (n) a is -4, b is -4 (o) x is 5 and y is 4 (p) value is 2.20 (q) False (need an array of type char with a size of at least 12 characters to store this 11-char string) (r) str=I Hope To Do Well On This Exam. (s) correct answer is (s-3) a value outside the range of actual data values indicating that the end of the data has been reached. (t) correct answer is (t-1) emp1.age = 47; 2.(a) int sum = 0, i; for (i=1; i<= 5; i++) { sum = sum + i; } (b) char f; /* suppose a value is now entered for f - code not shown */ switch(f) { case ‘u’: printf("unleaded petrol\n"); break; case ‘p’: printf("premium petrol\n"); break; case ‘d’: printf("diesel\n"); break; default: printf("incorrect value entered\n"); break; } (c) int zerofinder(int A[], int size) { int j; for (j=0; j void main(void) { FILE *fptr1, *fptr2; int inp; fptr1 = fopen("input.dat", "r"); fptr2 = fopen("output2.dat", "w"); while (fscanf(fptr1, "%d", &inp)==1){ if (inp >= -1 && inp <= 4){ fprintf(fptr2, "%d ", inp); } } fclose(fptr1); fclose(fptr2); }