FORM 1 (Please put your name and form # on the scantron!!!!)

Similar documents
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Stack Allocation. Run-Time Data Structures. Static Structures

Answers to Review Questions Chapter 7

Chapter 5 Functions. Introducing Functions

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

The C Programming Language course syllabus associate level

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Arrays in Java. Working with Arrays

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Passing 1D arrays to functions.

Chapter 5 Names, Bindings, Type Checking, and Scopes

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

Parameter Passing in Pascal

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Basics of I/O Streams and File I/O

C++FA 5.1 PRACTICE MID-TERM EXAM

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Chapter 13 Storage classes

Two-Dimensional Arrays Summer 2010 Margaret Reid-Miller

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

Moving from CS 61A Scheme to CS 61B Java

C++ INTERVIEW QUESTIONS

An Incomplete C++ Primer. University of Wyoming MA 5310

Curriculum Map. Discipline: Computer Science Course: C++

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Comp151. Definitions & Declarations

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

Java Interview Questions and Answers

What Is Recursion? Recursion. Binary search example postponed to end of lecture

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Sources: On the Web: Slides will be available on:

El Dorado Union High School District Educational Services

In this Chapter you ll learn:

Moving from C++ to VBA

Recursion. Slides. Programming in C++ Computer Science Dept Va Tech Aug., Barnette ND, McQuain WD

Stacks. Linear data structures

Computer Programming I

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

13 Classes & Objects with Constructors/Destructors

Java Application Developer Certificate Program Competencies

Sample Questions Csci 1112 A. Bellaachia

arrays C Programming Language - Arrays

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

Object Oriented Software Design II

Database Programming with PL/SQL: Learning Objectives

Introduction to Java. CS 3: Computer Programming in Java

Unit Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

Part I. Multiple Choice Questions (2 points each):

Introduction to Java

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Section of DBMS Selection & Evaluation Questionnaire

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

J a v a Quiz (Unit 3, Test 0 Practice)

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

8.1. Example: Visualizing Data

Chapter 8 Selection 8-1

Habanero Extreme Scale Software Research Project

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

Glossary of Object Oriented Terms

Data Structures using OOP C++ Lecture 1

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

VB.NET Programming Fundamentals

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Informatica e Sistemi in Tempo Reale

5 Arrays and Pointers

Object Oriented Software Design II

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

Pemrograman Dasar. Basic Elements Of Java

Pseudo code Tutorial and Exercises Teacher s Version

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

COMPUTER SCIENCE 1999 (Delhi Board)

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

C++FA 3.1 OPTIMIZING C++

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Computer Science III Advanced Placement G/T [AP Computer Science A] Syllabus

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Project 2: Bejeweled

Chapter 2: Elements of Java

Class 16: Function Parameters and Polymorphism

PostgreSQL Functions By Example

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

AP Computer Science Java Subset

Solving Problems Recursively

COMPUTER SCIENCE. Paper 1 (THEORY)

Parameter Passing. Standard mechanisms. Call by value-result Call by name, result

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Transcription:

CS 161 Exam 2: FORM 1 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. To declare a C-string, you should use the type expression string *. 2. Memory cannot be allocated after a program is already running. 3. A static array name is a pointer constant because the address it represents cannot be changed during run-time. 4. A one-dimensional array can only store elements of a single data type, but a two-dimensional array can hold data of two different data types. 5. An element of a two-dimensional array is referenced to by the array name and two subscripts, first the element row number and then the element column number. 6. When you pass an array as an argument to a function, the function can modify the contents of the array. 7. To assign the entire contents of one array to another, you can use the assignment operator. 8. The amount of memory used by an array depends solely on the number of elements the array can hold. 9. If a C++ program contains the following array definition int score[10]; the following statement would store 100 in the first array element: score[1] = 100; 10. If a function has no return statement, the flow of control moves to the next function in the file when the closing brace of the function body is reached. 11. It is possible for a function to have some parameters with default arguments and some without. 12. Recursive algorithms tend to be less efficient than iterative algorithms. 13. A recursive function can have local variables. 14. Each recursion causes a new frame to be placed on the stack.

Multiple Choice (3 pts each) 15. A function can have zero to many parameters, and it can have return value(s). a. a maximum of ten b. no c. either zero or one d. either one or two e. zero to many 16. In a function prototype, in addition to the name of the function, you are required to furnish a. the data type of the return value. b. an identifier name for each parameter. c. a data type for each parameter. d. all of the above. e. A and C, but not B. 17. A variable is defined inside the body of a function and is not accessible outside that function. a. global b. counter c. local d. reference e. constant 18. When a function just needs to use a copy of an argument passed to it, the argument should normally be passed a. as a default argument. b. by variable. c. by value. d. as a string. e. by reference. 19. When used as a parameter, a variable allows a function to access and modify the original argument passed to it. a. default value b. value c. static d. reference e. floating-point 20. When more than one function has the same name they are called functions. a. sister b. overloaded c. renamed d. parallel e. identical

21. The statement causes a function to end and the flow of control to move back to the point where the function call was made. a. exit b. end c. return d. break e. continue 22. What will the following code output? int number = 22; int *var = &number; cout << var << endl; a. The address of the number variable b. 22 c. An asterisk followed by 22 d. An asterisk followed by the address of the number variable 23. Unlike regular variables, arrays can hold multiple a. values. b. named constants. c. variables. d. data types. e. operators. 24. Given the following function definition void calc (int a, int& b) int c; c = a + 2; a = a * 3; b = c + a; What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; calc(x, y); cout << x << " " << y << endl; a. 1 2 b. 1 6 c. 3 6 d. 1 14 e. None of these

25. When an array is passed to a function, it is actually the array that is passed. a. the data type and size of b. the value stored in the first element of c. the starting memory address of d. the data type and name of e. a copy of all the values in 26. The null terminator stands for the ASCII code a. 100. b. 1000. c. 57. d. 0. 27. The function int fact(int k) return k*fact(k-1); if (k==0) return 1; a. does not correctly handle its base case. b. computes the factorial on an integer k passed to it as parameter. c. returns the value 1 if it is passed a value of 0 for the parameter k. d. works for all non-negative values of k, but not for negative numbers. 28. If you leave out the size declarator in an array declaration a. you must furnish an initialization list. b. the value of each array element is set to a default value of 0. c. the array size defaults to 100 elements. d. the array will contain no elements. e. the array cannot be created 29. The, also known as the address operator, returns the memory address of a variable. a. exclamation point (! ) b. asterisk ( * ) c. percent sign (%) d. ampersand ( & ) 30. The statement double *num; a. initializes a variable called *num. b. defines a variable of type double called num. c. defines and initializes a pointer variable called num. d. defines a pointer variable called num.

31. Assuming that arr is an array identifier, the statement sum += *arr; a. will always result in a compiler error. b. adds the value stored in arr[0] to sum. c. is illegal in C++. d. adds the address of the pointer arr to sum. 32. The delete operator should only be used on pointers that a. point to storage allocated by the new operator. b. have not yet been used. c. have been correctly initialized. d. are appropriately dereferenced. 33. Which of the following statements is not valid C++ code? a. float num1 = &ptr2; b. int ptr = &num1; c. int ptr = int *num1; d. All of the above are valid. e. All of the above are invalid. 34. Which of the following statements correctly deletes a dynamically-allocated array pointed to by p? a. delete p; b. delete array p; c. delete [ ] p; d. p delete[ ]; 35. If arr is an array identifier and k is an integer, the expression arr[k] is equivalent to a. arr + k. b. arr + *k. c. *(arr + k). d. &arr[k]. 36. A recursive function that does not correctly handle its base case may a. cause a continuous chain of recursive calls. b. return FALSE and stop. c. reach the NULL terminator and stop. d. return 0 and stop.

37. What would be the result of the call dotask (5, 4), given the following definition? int dotask (int a, int b) if (a <= 2) return 5; else return dotask(a-1, b-1) + a + b; a. 5 b. 10 c. 17 d. 26 38. An array of characters ending with the null terminator is called a. a C++ String. b. a string class object. c. a C-string. d. a string literal. Extra Credit (2 pts each): 39. The of recursion is the number of times a recursive function calls itself. a. depth b. level c. type d. breadth 40. True (A) / False (B): C++ arrays check for out-of-range index values. 41. The statement int grades[ ] = 100, 90, 99, 80 ; is an example of a. default arguments. b. implicit array sizing. c. data encapsulation. d. an illegal array declaration. e. an illegal array initialization. 42. The expression strcmp("ab", "ab") returns a. the value equivalent to false. b. a non-zero positive integer c. a negative integer. d. the boolean value true.

43. An array called alist contains integers 5, 3, 7, 2, 8. What are the contents of alist after the function call workonarray (alist, 4), if and the definition of workonarray is: int workonarray (int a[], int n) if (n == 1) return a[0] + 3; else a[n] = workonarray (a, n-1); return 7; a. 5, 3, 8, 8, 8 b. 5, 6, 10, 5, 11 c. 5, 3, 8, 7, 7 d. 8, 6, 10, 5, 11