FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Similar documents
Homework #3 CS2255 Fall 2012

CS 161 Exam II Winter 2018 FORM 1

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

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Exam 3 Chapters 7 & 9

CS2255 HOMEWORK #1 Fall 2012

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

pointers + memory double x; string a; int x; main overhead int y; main overhead

Introduction to Computer Science Midterm 3 Fall, Points

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CSC 1300 Exam 4 Comprehensive-ish and Structs

Pointers. Variable Declaration. Chapter 10

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

What is an algorithm?

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

FORM 2 (Please put your name, form #, and section # on the scantron!!!!)

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

[0569] p 0318 garbage

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

C++ for Java Programmers

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

CS201- Introduction to Programming Current Quizzes

True or False (15 Points)

Pointers. Memory. void foo() { }//return

C Pointers. 6th April 2017 Giulio Picierro

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

THE GOOD, BAD AND UGLY ABOUT POINTERS. Problem Solving with Computers-I

Reference operator (&)

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Introduction to Programming using C++

Name Section: M/W or T/TH. True or False (14 Points)

Pointers, Arrays and C-Strings

Exercise 1.1 Hello world

C++ Programming: From Problem Analysis to Program Design, Third Edition

CS31 Discussion. Jie(Jay) Wang Week8 Nov.18

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Chapter 9: Pointers Co C pyr py igh i t gh Pear ea so s n n E ducat ca io i n, n Inc. n c.

CSE030 Fall 2012 Final Exam Friday, December 14, PM

Lecture 23: Pointer Arithmetic

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

Pointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Study Guide for Test 2

Pointers, Dynamic Data, and Reference Types

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Output of sample program: Size of a short is 2 Size of a int is 4 Size of a double is 8

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

True or False (12 Points)

Pointers and Strings Chapters 10, Pointers and Arrays (10.3) 3.2 Pointers and Arrays (10.3) An array of ints can be declared as

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Pointers II. Class 31

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body

9.2 Pointer Variables. Pointer Variables CS Pointer Variables. Pointer Variables. 9.1 Getting the Address of a. Variable

CS2141 Software Development using C/C++ C++ Basics

Type Aliases. Examples: using newtype = existingtype; // C++11 typedef existingtype newtype; // equivalent, still works

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Outline. Introduction. Pointer variables. Pointer operators. Calling functions by reference. Using const with pointers. Examples.

BITG 1113: Array (Part 1) LECTURE 8

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

VARIABLES & ASSIGNMENTS

UEE1302 (1102) F10 Introduction to Computers and Programming (I)

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CS162 - POINTERS. Lecture: Pointers and Dynamic Memory

Pointers. Reference operator (&) ted = &andy;

CS 103 Lab - Party Like A Char Star

CSCE 206: Structured Programming in C++


Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

2. It is possible for a structure variable to be a member of another structure variable.

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

CSCI-1200 Data Structures Spring 2014 Lecture 5 Pointers, Arrays, Pointer Arithmetic

Solution Manual for Data Structures and Problem Solving Using C++ 2nd edition by Mark A. Weiss

1. In C++, reserved words are the same as predefined identifiers. a. True

Increment and the While. Class 15

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

C++ PROGRAMMING LANGUAGE: DYNAMIC MEMORY ALLOCATION AND EXCEPTION IN C++. CAAM 519, CHAPTER 15

MM1_ doc Page E-1 of 12 Rüdiger Siol :21

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

CS201 Latest Solved MCQs

Chapter 11: Pointers

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

CSCI-1200 Data Structures Fall 2017 Lecture 5 Pointers, Arrays, & Pointer Arithmetic

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

COMP322 - Introduction to C++ Lecture 01 - Introduction

Name SECTION: 12:45 2:20. True or False (12 Points)

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Algorithms & Data Structures

CSC 211 Intermediate Programming. Arrays & Pointers

Introduction to Scientific Computing and Problem Solving

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

Transcription:

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. If a function has default arguments, they can be located anywhere in the parameter list. 2. When you pass an array as an argument to a function, the function can modify the contents of the array. 3. C++ limits the number of array dimensions to two. 4. The amount of memory used by an array depends upon the array's data type and the number of elements in the array. 5. An individual array element can be processed like any other type of C++ variable/object. 6. If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error. 7. With reference variables you can access, but you cannot modify, data in other variables. 8. It is legal to subtract a pointer variable from another pointer variable. 9. All array names are pointer constants because the address stored in it cannot be changed during runtime. 10. Assuming myvalues is an array of int values, and index is an int variable, both of the following statements do the same thing. cout << myvalues[index] << endl; cout << *myvalues + index << endl; 11. C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array. 12. The C++ compiler performs strict array bounds checking when it encounters an array of characters. 13. The strlen function returns a C-style string's length and adds one for \0. 14. You may use the == operator to compare all the elements between two C-style strings. 15. Overloaded functions may have the same name, as long as their parameter lists or return types are different. 16. A recursive function can have only one recursive case. 17. These two declarations are exactly the same char city[] = {'D', 'a', 'l', 'l', 'a', 's'; char city[] = "Dallas";

Multiple Choice (3 pts each): 18. These types of arguments are passed to parameters automatically if no argument is provided in the function call. A) Local B) Default C) Global D) Relational 19. In C++, a C-string is a sequence of characters stored in consecutive memory, terminated by a. A) period B) space C) null character D) semicolon 20. Which of the following function declarations is correct? A) int f(int a[3][], int rowsize); B) int f(int a[][], int rowsize, int columnsize); C) int f(int a[][3], int rowsize); D) int f(int[][] a, int rowsize, int columnsize); 21. What is the output of the following function call, given the function definition below? cout << tester (4); // function call int tester (int n) { // function definition if (n == 1) return 3; else return 2 * tester ( n 1); A) 3 B) 6 C) 12 D) 24 22. The name of an array stores the of the first array element. A) memory address B) value C) element number D) data type 23. To assign the contents of one array to another, you must use. A) the assignment operator with the array names B) the equality operator with the array names C) a loop to assign the elements of one array to the other array D) Any of these

24. The function int fact(int k) { return k*fact(k-1); if (k==0) return 1; A) computes the factorial on an integer k passed to it as parameter. B) returns the value 1 if it is passed a value of 0 for the parameter k. C) does not correctly handle its base case. D) works for all non-negative values of k, but not for negative numbers. E) None of the above 25. What is the output of the following code? #include <iostream> using namespace std; int main() { int matrix[3][3] = {{1, 2, 3,{4, 5, 6,{8, 9, 10; int sum = 0; for (int i = 0; i < 3; i++) cout << matrix[i][1] << " "; return 0; A) 3 6 10 B) 1 4 8 C) 1 2 3 D) 4 5 6 E) 2 5 9 26. An array can store a group of values, but the values must be: A) the same data type B) each of a different data type C) constants D) integers 27. To pass an array as an argument to a function, pass the of the array. A) contents B) size, expressed as an integer C) name D) value of the first element 28. An array of string objects that will hold 5 names would be declared using which statement? A) string names[5]; B) string names(5); C) string names5; D) string[5] names; will work.

29. It is to pass an argument to a function that contains an individual array element, such as numbers[3]. A) illegal in C++ B) legal in C++ C) not recommended by the ANSI committee D) not good programming practice 30. What is the last legal subscript/index that can be used with the following array? int values[5]; A) 0 B) 5 C) 6 D) 4 31. Which of the following statements is not valid C++ code? A) int ptr = &num1; B) int ptr = int *num1; C) float num1 = &ptr2; D) All of these are valid. are valid. 32. What will the following code display? int numbers[5] = { 99, 87, 66, 55, 101 ; for (int i = 1; i < 4; i++) cout << numbers[i] << endl; A) 99 87 66 55 101 B) 87 66 55 101 C) 87 66 55 D) Nothing. This code has an error. 33. When you work with a dereferenced pointer, you are actually working with. A) a variable whose memory has been allocated B) a copy of the value pointed to by the pointer variable C) the actual value/contents of the variable whose address is stored in the pointer variable D) All of these

34. What will the following code do? const int SIZE = 5; double x[size]; for(int i = 1; i <= SIZE; i++) x[i] = 0.0; A) Each element in the array is initialized to 0.0 B) Each element in the array, except the first, is initialized to 0.0 C) Each element in the array, except the first and the last, is initialized to 0.0 D) This code has an error that may cause it to crash. 35. 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 36. Which of the following statements deletes memory that has been dynamically allocated for an array? A) int array = delete memory; B) int delete[ ]; C) delete [] array; D) new array = delete; E) delete array []; 37. Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; A) The value stored in the variable whose address is contained in ptr. B) The string "*ptr". C) The address of the variable stored in ptr. D) The address of the variable whose address is stored in ptr. 38. Look at the following code: int numbers[5] = {0, 1, 2, 3, 4 ; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true? A) ptr will hold the address of numbers[0]. B) ptr will hold the address of the 2nd byte within the element numbers[0]. C) ptr will hold the address of numbers[1]. D) This code will not compile.

39. Dynamic memory allocation occurs. A) when a new variable is created by the compiler B) when a new variable is created at runtime C) when a pointer fails to dereference the right variable D) when a pointer is assigned an incorrect address Extra Credit (2 pts each): 40. When the less than ( < ) operator is used between two pointer variables, the expression is testing whether. A) the value pointed to by the first is less than the value pointed to by the second B) the value pointed to by the first is greater than the value pointed to by the second C) the address of the first variable comes before the address of the second variable in the computer's memory D) the first variable was declared before the second variable 41. Look at the following statement: sum = (*array)++; This statement. A) is illegal in C++ B) will always result in a compiler error C) assigns the dereferenced pointer's value, then increments the pointer's address D) increments the dereferenced pointer's value by one, then assigns that value 42. Not all arithmetic operations may be performed on pointers. For example, you cannot or a pointer. A) multiply, divide B) add, subtract C) +=, -= D) increment, decrement 43. True(A)/False(B) The stack frames in nested function calls are handled in a last-in/ first-out order. 44. True(A)/False(B) The following function will recursively add the values of each element in an array and return the sum. double recsum(double array[], int count) { if (count > 0) { return recsum(array, count--) + array[count-1];