Exam 3 Chapters 7 & 9

Similar documents
Homework #3 CS2255 Fall 2012

CSC 1300 Exam 4 Comprehensive-ish and Structs

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

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

CS2255 HOMEWORK #1 Fall 2012

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

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.

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

Pointers, Dynamic Data, and Reference Types

What is an algorithm?

CS 161 Exam II Winter 2018 FORM 1

CS201- Introduction to Programming Current Quizzes

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

Pointers II. Class 31

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

a data type is Types

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

Introduction to Computer Science Midterm 3 Fall, Points


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

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

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

Question 2. [5 points] Given the following symbolic constant definition

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

Variables, Memory and Pointers

Dynamic Memory Allocation

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

Chapter 7 - Notes User-Defined Functions II

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.

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

C Pointers. 6th April 2017 Giulio Picierro

Launchpad Lecture -10

Pointers Pointer Variables. Pointer Variables Getting the Address of a Variable. Each variable in program is stored at a

Pointers! Arizona State University 1

CMSC202 Computer Science II for Majors

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

Arrays. Arizona State University 1

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

cout << "How many numbers would you like to type? "; cin >> memsize; p = new int[memsize];

Array Elements as Function Parameters

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

Memory and Pointers written by Cathy Saxton

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. Array Terminology. Array Terminology 8/23/2014. Arrays Hold Multiple Values

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY

UNIT- 3 Introduction to C++

CSI33 Data Structures

Lectures 6/7 Pointers and Dynamic Arrays

True or False (15 Points)

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

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

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

[0569] p 0318 garbage

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

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

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Pointers. Variable Declaration. Chapter 10

CS162 - POINTERS. Lecture: Pointers and Dynamic Memory

Reference operator (&)

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

CSE030 Fall 2012 Final Exam Friday, December 14, PM

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 8: Dynamic Memory Allocation

Chapter 9. Pointers and Dynamic Arrays

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

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

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

Week 3: Pointers (Part 2)

Learning Objectives. Introduction to Arrays. Arrays in Functions. Programming with Arrays. Multidimensional Arrays

Pointers and Dynamic Memory Allocation

C++ Final Exam 2017/2018

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

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

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

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

CSCE 2014 Final Exam Spring Version A

M1-R4: Programing and Problem Solving using C (JULY 2018)

Chapter 7: Arrays Copyrig opy ht rig 2012 Pea e rson a Educa Educ ti a on, Inc I. nc

Review Questions for Final Exam

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

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

Lecture 23: Pointer Arithmetic

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.

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

Structured Data. CIS 15 : Spring 2007

Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming

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

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

COMPUTER APPLICATION

KOM3191 Object Oriented Programming Dr Muharrem Mercimek ARRAYS ~ VECTORS. KOM3191 Object-Oriented Computer Programming

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

CSCI 262 Data Structures. Arrays and Pointers. Arrays. Arrays and Pointers 2/6/2018 POINTER ARITHMETIC

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

CS201 Latest Solved MCQs

CSCE 206: Structured Programming in C++

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. Array Terminology. Array Terminology

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

Transcription:

Exam 3 Chapters 7 & 9 CSC 2100-002/003 29 Mar 2017 Read through the entire test first BEFORE starting Put your name at the TOP of every page The test has 4 sections worth a total of 100 points o True/False 10 questions, 20 points o Multiple Choice 10 questions, 30 points o Short Answer 2 questions, 10 points o Code 1 question, 40 points Section 1 True / False 1. T F Each individual element of an array can be accessed by the array name and an element number, called a subscript. 2. T F The ampersand (&) is used to dereference a pointer variable in C++. 3. T F An individual array element can be processed like any other type of C++ variable. 4. T F With pointer variables you can access, but you cannot modify, data in other variables. 5. T F Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement. array1 = array2; 6. T F A pointer can be used as a function argument, giving the function access to the original argument. 7. T F It is legal to subtract a pointer variable from another pointer variable. 8. T F C++ limits the number of array dimensions to two. 9. T F 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 10. T F The amount of memory used by an array depends upon the array's data type and the number of elements in the array - 1 -

Section 2 Multiple Choice 11. Which statement displays the address of the variable num1? a. cout << num1; b. cout << *num1; c. cin >> &num1; d. cout << &num1 12. What does the following statement do? vector<int> v(10); a. It creates a vector object and initializes all of its elements to the value 10. b. It creates a vector object with a starting size of 10. c. It creates a vector object and initializes the first element with the value 10. d. It creates a vector object that can store only values of 10 or lessl 13. The following statement: int *ptr = new int; a. results in a compiler error b. assigns an integer less than 32767 to the variable named ptr c. assigns an address to the variable named ptr d. creates a new pointer named int 14. What will the following code do? const int SIZE = 5; double x[size]; for(int i = 2; 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. An error will occur when the code runs 15. A pointer variable is designed to store. a. any legal C++ value b. only floating-point values c. a memory address d. an integer - 2 -

16. 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 the array elements c. All array elements will default to values of zero d. Your array will contain no elements 17. When you pass a pointer as an argument to a function, you must. a. declare the pointer variable again in the function call b. dereference the pointer variable in the function prototype c. use the #include<func_ptr.h> statement d. not dereference the pointer in the function's body 18. A two-dimensional array can have elements of data types a. one b. two c. four d. A or B 19. 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 20. Arrays may be at the time they are. a. resized, executed b. re-scoped, deleted c. initialized, declared d. pre-compiled, typecast - 3 -

Section 3 Short Answer 21. Explain two differences between heap and stack memory 22. Explain how parallel array works and why are they better than multi-dimensional arrays - 4 -

Section 4 Code 22. Write a program that : a. Creates a dynamically allocated array of size 2 b. Stores values inputted by the user into the array until a sentinel value is reached c. Resizes the array to currentsize x 2 when necessary d. Creates a second array AFTER the sentinel is reached that stores all the values in the first array, but in reverse order e. Displays the contents of both arrays f. Your program should use at LEAST 2 functions to accomplish the above tasks. - 5 -