UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

Similar documents
Quiz1 Fall 2007 October 2 nd, UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated :October 2nd, 2007.

UNIVERSITY OF WINDSOR Fall 2006 QUIZ # 1. Examiner:Ritu Chaturvedi Dated : Oct 3rd, Student Name: Student Number:

UNIVERSITY OF WINDSOR Winter 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated : Feb 7 th, Student Name: Student Number:

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

AMCAT Automata Coding Sample Questions And Answers

Decision Making and Loops

CGS 3460 Summer 07 Midterm Exam

Functions. Arash Rafiey. September 26, 2017

Make sure the version number is marked on your scantron sheet. This is Version 1

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Arrays and Applications

M1-R4: Programing and Problem Solving using C (JAN 2019)

What we have learned so far

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

Principles of Programming. Chapter 6: Arrays

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Introduction to Computer Science Midterm 3 Fall, Points

Government Polytechnic Muzaffarpur.

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Pointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

Arrays and Strings. Arash Rafiey. September 12, 2017

Computer Science & Engineering 150A Problem Solving Using Computers

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

Arrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #07. Topic: Pointer in C Date:

Subject: Fundamental of Computer Programming 2068

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Slides adopted from T. Ferguson Spring 2016

Unit 3 Decision making, Looping and Arrays

Pointers. Pointer Variables. Chapter 11. Pointer Variables. Pointer Variables. Pointer Variables. Declaring Pointer Variables

Solutions to Assessment

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Practice Sheet #07 with Solutions

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

Scope. Scope. Region of a program in which a defined object is visible. Defined Objects. Two types of regions. Variables Functions

Initialisation of an array is the process of assigning initial values. Typically declaration and initialisation are combined.

At the end of this module, the student should be able to:

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

This exam is to be taken by yourself with closed books, closed notes, no calculators.

Decisions II. Switch Statement. If else allows a 2 way decision Switch allows for n-way decisions

Control Structure: Loop

DECISION MAKING STATEMENTS

Arrays. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

Lecture 6 Sorting and Searching

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CSE 5A Final Fall 2006

Procedural Programming

Language comparison. C has pointers. Java has references. C++ has pointers and references

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

More Arrays. Last updated 2/6/19

Lecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?

For questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

CS 101, Spring 2016 March 22nd Exam 2

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

Loops / Repetition Statements

Questions Bank. 14) State any four advantages of using flow-chart

Loops / Repetition Statements

CS16 Exam #1 7/17/ Minutes 100 Points total

Basic and Practice in Programming Lab7

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

WARM UP LESSONS BARE BASICS

Module 6: Array in C

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Structured programming

n Group of statements that are executed repeatedly while some condition remains true

"'"' .;, b) F or ( c = l ; c <= 10,"' c++ ) X { JJ. ~. Computer Programming I COME Midterm Examination. Fall November 2016

Binary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal

Decimal Representation

Programming & Data Structure Laboratory. Day 2, July 24, 2014

Computer Programming Lecture 12 Pointers

Question 2. [2 points] Which of the following is a correct statement to obtain user input? (Assume that fleems is an int variable.

ESC101N: Fundamentals of Computing End-sem st semester

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Chapter 7 Functions. Now consider a more advanced example:

COS 126 General Computer Science Spring Written Exam 1

Problem: Read 10 numbers from the keyboard and store them

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement

'C' Programming Language

only in the space provided. Do the rough work in the space provided for it. The question paper has total 12 pages.

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Outline Introduction Arrays Declaring Arrays Examples Using Arrays Passing Arrays to Functions Sorting Arrays

Arrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array

Do not start the test until instructed to do so!

ECE15: Introduction to Computer Programming Using the C Language Lecture 6: Arrays

This is CS50. Harvard University Fall Quiz 0 Answer Key

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

return return else return

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination

Transcription:

UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 2 Solution Examiner : Ritu Chaturvedi Dated :November 27th, 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 5 True/False questions and 30 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: Multiple-Choice Questions(30X2=60 marks) 1. What is the output of the following program? #include<stdio.h> void swap(int *, int ); void main(void) int x = 3, y = 4; swap(&x, y); printf( In main, x= %d, y = %d\n, x, y); void swap(int* a, int b) int temp; temp = *a; *a = b; b = temp; a. Will not compile because the & is missing for the function parameter b. b. 4 3 c. 3 4 d. 3 3 e. 4 4 2. For the function definition of swap given above, which one of the 2 parameters (a and b) is called by reference? a. Both a and b b. Only a c. Only b d. Neither a nor b 2

3. Which of the types listed below can be the type of a function output parameter? a. int * b. float * c. char * d. all of the above e. none of the above 4. If the input to the program segment at the right is 85, what is its output? a. A scanf("%d", &s); if (s >= 90) b. B printf("a\n"); else if (s >= 70) c. C printf("c\n"); else if (s >= 80) d. D printf("b\n"); else e. C printf("d\n"); B 5. In function apart defined below, how many of the parameters are considered output parameters? void apart(float x, int *wholep, float *fracp) *wholep = (int)x; *fracp = x - *wholep; a. 0 b. 1 c. 2 d. 3 e. all 3

6. What gets stored in variable x after the given if-else is executed. int x = 15; if (x = 5) x = x + 5; else x = x - 5; a. 5 b. 10 c. 15 d. 20 Questions 7 and 8 are based on the following for loop. Assume x is an integer. for (x=5; x<=22; x=x+7) printf( %d,x); 7. What gets printed by the for loop? a. 5 12 19 b. 5 7 12 19 c. 7 14 21 d. 1 8 15 22 8. What value of x gets printed after the loop ends? a. 22 b. 23 c. 5 d. 5 12 19 4

Use the following declaration to answer questions 9,10,11 and 12. int a[50]; 9. Which of the following is a valid instruction that reads a value from the keyboard into array element 9 of array a? a. scanf( %d, &a[i]); b. scanf( %d, &a); c. scanf( %d, a[9]); d. scanf( %d, &a[9]); 10. What is the maximum valid subscript value for array a? a. 0 b. 49 c. 50 d. a[50] e. none of the above 11. Which of the following is a valid instruction that assigns a value of 45 to array element 9 of array a? a. a[i] = 45; b. a[45] = 9; c. a[9] = 45; d. a[] = 45; a. none of the above 12. What is the effect of the following program segment? int i, temp = 0; for (i = 1; i < 50; ++i) if (a[i] > a[0]) temp = temp + 1; a. Arranges the elements of array a in ascending order. b. Counts the number of elements of array a greater than its initial element a[0]. c. Reverses the numbers stored in the array. d. Puts the largest value in the last array position.. 5

13. How long does the following code run? for(i=10;i>20;i=i+5) printf( %d,i); a. Never b. Three times c. Forever d. Two times 14.What is printed by the following program fragment? if(3==3 &&!(2==3)) printf( *** ); else printf(??? ); printf(! ); a. *** b. ***! c.??? d.???! 15.What is the value of k after the following statement is executed, given that i and k are integers and i=3 and k = 0. k = ++i; a. 4 b. b. c. 5 d. 3 e. none of the above 6

Next four questions will be based on the following program segment. int i, a, j = 5, b = 11; for ( i = 1; i <= 10 ; i = i+ 5) a = j % i ; for ( j = 0; j < 10; j = j + 10) b = b + j; j = j + 1; 16. What is the value of i after the execution of the above code? a. 10 b. 5 c.17 d. 11 e. None of above 17 What is the value of j after the execution of the above code? a. 10 b. 0 c. 5 d. 11 e. None of above 18 What is the value of a after the execution of the above code? a. 10 b. 5 c. 11 d. 2 e. None of above 19. at is the value of b after the execution of the above code? a. 0 b. 26 c. 5 d. 11 e. None of above 20. What value is assigned to x when y is 15.0? if (y< 15.0) if ( y >= 0.0) x = 5 * y; else x = 2 * y; else x = 3 * y; a. 45.0 b. 75.0 c. 30.0 d. 15.0 7

21. How many times does the following while loop run? float n; int i = 0; printf( Watch out! Here come a bunch of fractions \n ); while (i < 30) n = 1 / i; printf( %f \n,n); printf( That s all, folks!\n ); a. 30 times b. 31 times c. infinite times d. 0 times e. none of the above 22. Which of the following statements can be used to assign values 1,2,3,4,5,6,7 to the array a using for loop. a. for(i=0; i<7; i++) a[i] = i; b. for(i=0; i<7; i++) a[i] = i + 1; c. for(i=1; i<=7; i++) a[i] = i; d. for(i=1; i<=7; i++) a[i] = i + 1; b. none of the above 23. Which of the following is a valid declaration for the array a used in question 22. a. int a[7]; b. int a[1,2,3,4,5,6,7]; c. int a[6]; d. int a[0][7]; 8

24. Assuming that a 3-by-4 array is declared as int a[3][4], Which of the following statements will assign a value of 6 to the element at 1 st row and 2 nd column of a. a. a[0,1] = 6; b. a[0][1] = 6; c. a[1,0]=6; d. a[1][0] = 6; e. a[3][4]=6; 25. Given x = 4, y = 3, and operator = 2, what is the final value of x after the following switch statement is executed? switch (operator) case 1: x = x + y; case 2: x = x - y; case 3: x = x * y; case 4: x = x / y; a. 1 b. 3 c. 1.33 d. 7 9

Question 26 30 are based on the program given below : #include <stdio.h> int a=10; int b=4; int c=4; int fun(int,int *,int *); void main(void) int a=9; int b=1; a=fun(a, &b, &c); //end of main int fun(int u, int * v, int * w) *v = a / b; c = *v + a; *w = u + c; a = c + b; b = a + *v; return u + *w; Answer questions 26-30 after execution of the above program. 26. What is the value of a in main? a. 25 b. 2 c.30 d. 27 e. None of above 27. What is the value of b in main? a. 25 b. 2 c.30 d. 27 e. None of above 28. What is the value of a in Global Area? a. 25 b. 27 c. 21 d. 30 29. What is the value of b in Global Area? a. 25 b. 2 c.30 d. 27 e. None of above 30. What is the value of c in Global Area? a. 25 b. 2 c.30 d. 27 e. None of above 10

Section II: State True / False for questions 31-35 (5 X 2 = 10 marks). (TRUE = A, FALSE = B) 31. The default case is required in a switch statement.false 32. The body of a for loop might not get executed at all.true 33. Sentinel-controlled loops do not know upfront the number of iterations to execute. True 34. Functions cannot have more than one output parameters. False 35. The data-type of an integer array declared as int a[10] is an int. False 11