CS 161 Exam II Winter 2018 FORM 1

Similar documents
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):

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

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

CSC 1300 Exam 4 Comprehensive-ish and Structs

Exam 3 Chapters 7 & 9

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

Homework #3 CS2255 Fall 2012

[0569] p 0318 garbage

Variables, Memory and Pointers

CS201- Introduction to Programming Current Quizzes

Introduction to Computer Science Midterm 3 Fall, Points

a data type is Types

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

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

REFERENCES, POINTERS AND STRUCTS

Pointers II. Class 31

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

CS2255 HOMEWORK #1 Fall 2012

Linked Lists CS 16: Solving Problems with Computers I Lecture #16

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

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

Chapter 10. Pointers and Dynamic Arrays. Copyright 2016 Pearson, Inc. All rights reserved.

Dynamic Allocation of Memory

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

Exercises with Linked Lists CS 16: Solving Problems with Computers I Lecture #15

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

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

Chapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Dynamic Allocation of Memory

Pointers and References

Introducing C++ to Java Programmers

Pointers. Addresses in Memory. Exam 1 on July 18, :00-11:40am

CA31-1K DIS. Pointers. TA: You Lu

Memory Management. CS31 Pascal Van Hentenryck CS031. Lecture 19 1


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

Pointers and Dynamic Memory Allocation

Object-Oriented Programming for Scientific Computing

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

Pointers, Dynamic Data, and Reference Types

CS162 - POINTERS. Lecture: Pointers and Dynamic Memory

CSC 211 Intermediate Programming. Pointers

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

Chapter 9. Pointers and Dynamic Arrays

What is Pointer? Pointer is a variable that holds a memory address, usually location of another variable.

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.

Pointers. A pointer value is the address of the first byte of the pointed object in the memory. A pointer does not know how many bytes it points to.

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

CMSC 341 Lecture 2 Dynamic Memory and Pointers

Introduction to Scientific Computing and Problem Solving

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

Please refer to the turn-in procedure document on the website for instructions on the turn-in procedure.

Suppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; }

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

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

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

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

Dynamic memory. EECS 211 Winter 2019

Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31.

内存管理. Memory management

CS 31 Review Sheet. Tau Beta Pi - Boelter Basics 2. 2 Working with Decimals 2. 4 Operators 3. 6 Constants 3.

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11

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

Chapter 9: Pointers. Copyright 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved.

Chapter 9: Getting the Address of a Variable. Something Like Pointers: Arrays. Pointer Variables 8/23/2014. Getting the Address of a Variable

Pointers and Terminal Control

Software Design and Analysis for Engineers

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

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

Constants, References

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Short Notes of CS201

Programming in C/C Lecture 2

6. Pointers, Structs, and Arrays. 1. Juli 2011

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

University of Toronto

What will the output of the following code snippet be? Why? What is a safer alternate implementation?

CPSC 427: Object-Oriented Programming

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

Functions. (transfer of parameters, returned values, recursion, function pointers).

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 (!

CS201 - Introduction to Programming Glossary By

Tokens, Expressions and Control Structures

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

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

What have we learned about when we learned about function parameters? 1-1

1 Memory management in C++

Outline. A C++ Linked Structure Class A C++ Linked List C++ Linked Dynamic Memory Errors In-class work. 1 Chapter 11: C++ Linked Structures

Part V. Memory and pointers. Philip Blakely (LSC) C++ Introduction 145 / 370

Intermediate Programming, Spring 2017*

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

CS 11 C track: lecture 5

CS201 Some Important Definitions

CSE 131 Compiler Construction Fall Project #2 -- Code Generation Due Date: Friday, December 4 th, 11:59pm

Lecture 2, September 4

Pointers. Pointers. Pointers (cont) CS 217

Transcription:

CS 161 Exam II Winter 2018 FORM 1 Please put your name and form number on the scantron. True (A)/False (B) (28 pts, 2 pts each) 1. The following array declaration is legal double scores[]={0.1,0.2,0.3; 2. The following array has 12 indexed variables. int myarray[12]={1,2,3,6,5,4,7,1,2; 3. Indices are numbered starting at 1. 4. If a * is used in a declaration of a variable, it is dereferencing that variable. 5. An & in a parameter listing indicates that the variable will be passed via a pointer. 6. The pass by value method of passing arguments allows for the passed value to be altered at the address of its variable. 7. The heap is a subsection of memory which will be automatically freed at the end of a function. 8. An example of a memory leak is when memory is left allocated on the heap without a way to accesses it. 9. Recursion must have a base case in order to stop. 10. Following code means p is getting the address of a. int p = *a; 11. A segmentation fault may occur as a result of attempting to access memory the program does not have access to. 12. C++ limits the number of array dimensions to two. 13. Arrays may only be declared dynamically. 14. C-style strings and C++ strings are the same thing.

Multiple Choice (72 pts, 3 pts each) 15. What are the valid indices for the array shown below? int myarray[25]; a. 0-25 b. 0-24 c. 1-25 d. 1-24 16. Which of the following assigns to p1 the pointer to the address of value? a. *p1=&value; b. p1=value; c. p1=&value; d. &p1 = *value; 17. Call-by-reference parameters are passed a. nothing b. the actual argument. c. the value in the actual argument. d. the address of the argument. 18. Which of the following statements correctly prints out the value that is in the memory address that the pointer p1 is pointing to? a. cout << &p1; b. cout << p1; c. cout << int* p1; d. cout << *p1; 19. What is the output of the following code? int *p1, *p2; p1 = new int; p2 = new int; *p1=11; *p2=0; p2=p1; cout << *p1 <<" " << *p2 << endl; a. 11 0 b. 0 11 c. 11 11 d. 0 0

20. Which of the following correctly declares a dynamic array of strings? a. p1 = new string(13); b. p1 = new string[]; c. p1 = new string[13]; d. p1 = new stringarray(13); 21. Which of the following statements correctly returns the memory from the dynamic array pointer to by p1 to the freestore? a. delete [] p1; b. delete p1[]; c. delete *p1; d. delete p1; 22. What is wrong with the following function body? void calculate(int count, float price, float& cost) { if (count < 0) else return; cost=0.0; cost=count*price; a. void functions may not have a return statement. b. void functions must return a value c. nothing d. can not mix reference and value parameters 23. If a program requires a dynamically allocate two-dimensional array, you would allocate the memory by using a. p1 = new int*[numrows]; for(int i=0; i < numrows; i++) p1[i] = new int[numcolumns]; b. p1 = new int*[numrows][numcolumns]; c. p1 = new[numrows][numcolumns]int; 24. Which of the following is not true? a. a pointer can be assigned the address of an array b. a static array can be assigned the value in a pointer variable c. if a pointer points to an array, it can be used in place of the array name d. if a pointer points to an array, the pointer does not know how many elements are in the array.

25. What is the output of the following function call, given the function definition below? int tester (int n) { if (n == 1) return 2; return 2 * tester (n-1); cout << tester(4); a. 2 b. 4 c. 16 d. 32 26. 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 a 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. 27. The name of an array stores the of the first array element. a. Value b. memory address c. element number d. data type 28. If you leave out the size declarator in an array definition a. you must furnish an initialization list b. you are not required to initialize array elements c. all array elements default to zero values d. your array will contain no elements 29. What is the last legal index that can be used with the following array? int values[5]; a. 0 b. 5 c. 6 d. 4 30. 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

31. A two-dimensional array of characters can contain a. strings of the same length b. strings of different lengths c. uninitialized elements d. All of these 32. The escape sequence that represents the null terminator is a. \n b. \t c. \0 d. Nullptr 33. The C-string company[12] can hold a. twelve characters b. thirteen characters c. eleven characters and the null terminator d. twelve characters and the null terminator 34. 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 35. 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 36. 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. 37. If a function calls itself, it is known as being. a. recursive b. repetitive c. distinct 38. Command line arguments allow user input to be taken before the program runs as. a. C++ strings b. C-style strings c. integers