UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 1 Solution Examiner:Ritu Chaturvedi Dated :October 2nd, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed. Examination Period is : 1 hour Answer all questions in the bubble sheet provided to you. You must use a pencil to mark the answer. There are 10 True/False questionsand 25 multiple choice questions. Select only one answer for each question. Write your name and student number on the examination paper as well as the bubble sheet and submit both the bubble sheet and the examination paper before you leave the exam hall. Total Marks : 70 Total number of pages : 11 There may be more than one possible answer. Choose the best possible answer. Good Luck!!! 1
SECTION I (TRUE OR FALSE ) : 10 X 2 = 20 marks. You may use choice of a for TRUE and choice of b for False: 1. All information that is to be processed by a computer must first be entered into memory via an input device. TRUE 2. A list of instructions provided to the computer is called a program. TRUE 3. Statements in a high-level language are converted to statements in machine language by a loader. FALSE 4. After the last statement of a function executes, control is transferred to the next defined function. FALSE 5. A syntax error in a program is an error that causes the program to produce incorrect output. FALSE 6. This assignment statement stores the sum of b and c in a: b + c = a; FALSE 7. A type char literal is enclosed in single quotes. TRUE 8. If the computer is switched off, data in secondary storage is usually not lost. TRUE 9. Functions are permitted to have only one input argument. FALSE 10. Because the following statement is a valid call to function wow, wow must be a void function. FALSE num = wow(x, y); 2
SECTION II : (Multiple Choice ) : 25 X 2 = 50 marks 1. The object file(a.out) is created by the. a. editor b. loader c. central processing unit d. compiler 2. A is a set of values and a set of operations on those values. a. file b. data type c. precedence rule d. library 3. Which of the types listed below can be the type of the result value returned by a userdefined function? a. int b. double c. char d. all of the above 4. Which of the following is not an advantage of a high-level language? a. It is easier to use than machine language. b. Its statements resemble English. c. It is easy for the machine to understand. d. All of the above 5. If num is a variable of type int and temp is a variable of type float, how could you correctly complete the scanf statement given below? scanf("%f%d", ); a. num, temp b. &num, &temp c. temp, num d. &temp, &num 3
6. A diagram of the hierarchical organization of the subproblems of a solution is called. a. stepwise refinement b. a structure chart c. a top-down approach d. function calls 7. Which one of the following expressions does not evaluate to 3? a. 2 + 16 % 5 b. 7-15 / 4 c. 6 * 5 / 10 d. 2-4 * 3 + 26 / 2 e. 8-5 8. Text enclosed in /* */ in a C program. a. gives instructions to the processor b. declares memory requirements c. is ignored by the C compiler d. causes a syntax error 9. A C compiler detects. a. syntax errors b. run-time errors c. result errors d. arithmetic faults 10. What value is assigned to q in the statement q = fun(2, 5, 4); if fun is defined as follows? int fun(int q, int b, int c) { int p; p = q * b + 2 * c; } return (p); 4
a. 11 b. 17 c. 18 d. 40 11. The formal parameters of the function fun are : a. q, fun b. p, b, c c. q, b, c d. p, q, b, c 12. What value gets stored in c after the following instructions are executed? int a,b,c; a = 5; b = 3; c = b * a / b % 2-1; a. 7 b. 7.5 c. -1 d. 0 13. The simple program segment for getting the sum of two numbers is. a. scanf( %d %d,num1, Num2); sum = Num1 + Num2; printf( %d,sum); b. scanf( %d%d,&num1,&num2); sum = Num1 + Num2; printf( %d,sum); c. scanf( %d %d,&num1, &Num2); average = (Num1 + Num2)/2; printf( %d,average); d. Read Num1, Num2; Sum = Num1 + Num2; Print Sum; 5
14. The correct statement which prints out the text Welcome, followed by a newline is : a. printf( Welcome\n ); b. printf(welcome, \n ); c. printf( Welcome\n ); d. printf(welcome\n); 15. The UNIX command on arc1.uwindsor.ca to compile a C program called a.c is: a. CC a.c b. cc a.c c. pico a.c d. a.out 16. Which of the following variable declarations are invalid? a. float num; b. int q; c. double plywood ; // there was a typo in the exam (missing ;) - d. all of the above // so, Question 16 will not be graded e. none of a,b,c 17. A location in the computer s memory that may contain different values at various times throughout the execution of a program is called a. a. constant b. variable c. keyword d. entity 6
Use the program given below to answer questions 18 and 19. #include <stdio.h> void module1(int, int); void main(void){ int a, b; a=5; b=16; module1(a,b); printf( %d %d \n,a, b); } //end of main void module1 (int a, int b){ a = a / 2; b = b % 2; } //end of function module1 18. What values of a gets printed when the above program is run? a. 0 b. 5 c. 16 d. 7 19. What values of b gets printed when the above program is run? a. 0 b. 5 c. 16 d. 7 20. Which of the following statements is a valid call to function abc? a. call abc; b. abc; c. p = abc(q); d. void abc(void); 7
21. Write a C assignment instruction for the following mathematical formula: a + b c + d a. a + b / c + d b. (a + b / c + d) c. (a + b) / (c + d) d. a / c + b / d Use the program below to anser questions 22 and 23. Line numbers are given for convenience: Line 1 #include <stdio.h> Line 2 void main(void){ Line 3 int a; Line 4 int b Line 5 scanf( %d, &a); Line 6 b = a + a; Line 7 printf( New b = %d \n, b); Line 8 } //end of main 22. Which line in the program above has an error? a. Line 3 b. Line 4 c. Line 5 d. Line 6 23. In which category does the above error fall into? a. Syntax error b. Run-Time error c. Logical error d. Undetected error 8
Use the program given below to answer questions 24 and 25 : #include <stdio.h> void main(void){ int m, n; m = 5; n = 7; m = m + 5; n = 3 * n; printf( %d \n, m); printf( %d \n, n); //1 st print statement //2 nd print statement } 24. What gets printed by the 1 st printf statement in the program above : a. 10 b. 35 c. 21 d. 12 25. What gets printed by the 2 nd printf statement in the program above : a. 10 b. 35 c. 21 d. 12 9