Midterm Review. Short Answer. Short Answer. Practice material from the Winter 2014 midterm. Will cover some (but not all) of the questions.

Similar documents
Tutorial 5. Overflow. Data Types. Structures. Call stack. Stack frames. Debugging Tips. CS 136 Winter 2019 Tutorial 5 1

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

Tutorial 5. Call Stack and Stack Frames. Memory Addresses and Pointers. Content vs Address of Pointers. scanf() function. Perils of Pointers

Tutorial 6. Memory Addresses and Pointers. scanf() function. Perils of Pointers. Function Pointers. Declarations vs. Definitions

Introduction to Pointers in C. Address operator. Pointers. Readings: CP:AMA 11, 17.7

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

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

CSE413 Midterm. Question Max Points Total 100

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

COMP 524 Spring 2018 Midterm Thursday, March 1

User Defined Functions

CS113: Lecture 5. Topics: Pointers. Pointers and Activation Records

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

APS105. Collecting Elements 10/20/2013. Declaring an Array in C. How to collect elements of the same type? Arrays. General form: Example:

APS105. Pointers. Memory RAM 11/5/2013. Pointers. Need a way to refer to locations of things. a pointer: Address. Example: In C

Chapter 8: Intraprogram Communication. Lecture 8 1

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

This is CS50. Harvard University Fall Quiz 0 Answer Key

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

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

Subprograms. Introduction to Programming (in C++) Subprograms: procedures and functions. Subprograms. Subprograms. Functions are defined as follows:

CS 108 Computing Fundamentals. October/November Array Bootcamp

CSE 142 Wi01 Midterm 2 page 1 of 6

CS 139 Practice Midterm Questions #2

Submit your answers to these questions to the Curator under Quizzes as HW08 by the posted due date and time. No late submissions will be accepted.

Class Information ANNOUCEMENTS

#3. (Recursion) Write a recursive function to compute f(x) = f(x - 1) + f(x - 2) with f(0) = 0 and f(1) = 1.

CS 61C: Great Ideas in Computer Architecture Introduction to C

CS 211 Programming Practicum Fall 2018

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Variables, Pointers, and Arrays

CS 61c: Great Ideas in Computer Architecture

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

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

Flow Chart. The diagrammatic representation shows a solution to a given problem.

CS536 Spring 2011 FINAL ID: Page 2 of 11

LECTURE 03 LINKED LIST

CS 314 Principles of Programming Languages. Lecture 9

CS2351 Data Structures. Lecture 7: A Brief Review of Pointers in C

Chapter 4. Section 4.4 Passing Parameters to Functions. CS 50 Hathairat Rattanasook

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

ECE264 Spring 2013 Final Exam, April 30, 2013

DECISION CONTROL AND LOOPING STATEMENTS

MIDTERM EXAMINATION - CS130 - Spring 2003

Programming for Electrical and Computer Engineers. Pointers and Arrays

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Lecture 5: Methods CS2301

University of Waterloo Midterm Examination Term: Winter Year: 2013

CS 0449 Sample Midterm

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Chapter 12: Pointers and Arrays. Chapter 12. Pointers and Arrays. Copyright 2008 W. W. Norton & Company. All rights reserved.

OBJECTIVE QUESTIONS: Choose the correct alternative:

Semantic Analysis. Lecture 9. February 7, 2018

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

ECEN 449 Microprocessor System Design. Review of C Programming. Texas A&M University

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Variables and Operators 2/20/01 Lecture #

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)

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

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

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.

Box-and-arrow Diagrams

Names, Scope, and Bindings

We would like to find the value of the right-hand side of this equation. We know that

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Introduction to C Final Review Chapters 1-6 & 13

CSE au Midterm Exam Nov. 2, 2018 Sample Solution

Learning to Program with Haiku

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

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

MCS 360 Exam 2 11 November In order to get full credit, you need to show your work.

APS105. Modularity. C pre-defined functions 11/5/2013. Functions. Functions (and Pointers) main. Modularity. Math functions. Benefits of modularity:

Warmup January 9th, What is the value of the following C expression? 8*9 % 10/ 2

COMP1917 Computing 1 Written Exam Sample Questions

Chapter 9: Functions. Chapter 9. Functions. Copyright 2008 W. W. Norton & Company. All rights reserved.

Procedure and Object- Oriented Abstraction

CS241 Computer Organization Spring Data Alignment

Pointers, Dynamic Data, and Reference Types

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

CMPT 125: Practice Midterm Answer Key

CSCI 2132 Software Development. Lecture 20: Program Organization

Question 2. [2 points] True False By default, structures are passed-by-reference.

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

CS 211 Programming Practicum Spring 2017

CSE 230 Intermediate Programming in C and C++ Functions

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

G. Tardiani RoboCup Rescue. EV3 Workshop Part 1 Introduction to RobotC

Names, Scope, and Bindings

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017

Functions. Systems Programming Concepts

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

CS 314 Principles of Programming Languages. Lecture 13

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

ESC101N: Fundamentals of Computing End-sem st semester

Remember to also pactice: Homework, quizzes, class examples, slides, reading materials.

Transcription:

Midterm Review Practice material from the Winter 2014 midterm. Will cover some (but not all) of the questions. Midterm content: Everything up to / including modules. CS 136 Spring 2018 Tutorial 7 1 List three advantages of modularization, and briefly explain. CS 136 Spring 2018 Tutorial 7 2 List three advantages of modularization, and briefly explain: Re-usability: Build programs faster, and build large programs more easily. Maintainability: Makes debugging and changing a program easier. Abstraction: No need to know / understand all parts to use them. Allows changing internals without breaking things. CS 136 Spring 2018 Tutorial 7 3

For positive integers, the C modulo operator (%) behaves the same as the Racket quotient function. C Which one is quotient again? CS 136 Spring 2018 Tutorial 7 4 For positive integers, the C modulo operator (%) behaves the same as the Racket quotient function. B *False. C Which one is quotient again? The modulo operator behaves the same as the remainder function. CS 136 Spring 2018 Tutorial 7 5 Briefly explain the special form provide in Racket, and why there is no equivalent in C. CS 136 Spring 2018 Tutorial 7 6

Briefly explain the special form provide in Racket, and why there is no equivalent in C: Gives identifiers program scope or specifies bindings available in a module. All functions and variables in C have program scope by default (and are therefore available to other modules). CS 136 Spring 2018 Tutorial 7 7 Every C module must have a main function. C True, but only on Tuesdays. CS 136 Spring 2018 Tutorial 7 8 Every C module must have a main function. B *False. C True, but only on Tuesdays. A module does not require a main function. (Example: The stack module from the last assignment). CS 136 Spring 2018 Tutorial 7 9

Racket uses dynamic typing. What kind of typing does C use? Give one advantage of the typing C uses. Provide a brief Racket example that demonstrates dynamic typing that isn t possible in C. CS 136 Spring 2018 Tutorial 7 10 Racket uses dynamic typing. What kind of typing does C use? Give one advantage of the typing C uses. Provide a brief Racket example that demonstrates dynamic typing that isn t possible in C: C uses static typing. Advantage: Built-in contract, can detect type errors at compile-time, fast (no run-time type checking). Example (there are many): (define dyntype (if (>= x 0) x invalid )) CS 136 Spring 2018 Tutorial 7 11 In C, (a!= 0) && (b/a == 2) will produce an error if a is 0. C Impossible to know without trying it. CS 136 Spring 2018 Tutorial 7 12

In C, (a!= 0) && (b/a == 2) will produce an error if a is 0. B *False. C Impossible to know without trying it. Because && is used, the first condition will short circuit the evaluation, preventing b/a from being executed. CS 136 Spring 2018 Tutorial 7 13 Briefly explain the purpose of requires and effects function documentation in C. CS 136 Spring 2018 Tutorial 7 14 Briefly explain the purpose of requires and effects function documentation in C: Requires: Identifies conditions that must be true when calling the function (e.g. restrictions on parameters). Effect: Identifies what a function prints, reads, or mutates. CS 136 Spring 2018 Tutorial 7 15

printf("hello!\n") is a C expression with a value of 7. C The only expressions in C are my cries of pain when I m forced to code in it. CS 136 Spring 2018 Tutorial 7 16 printf("hello!\n") is a C expression with a value of 7. A *True. C The only expressions in C are my cries of pain when I m forced to code in it. The return value of printf is the number of characters printed. CS 136 Spring 2018 Tutorial 7 17 Write the declaration for a C function add that takes two ints, x and y, and returns an int x+y. CS 136 Spring 2018 Tutorial 7 18

Write the declaration for a C function add that takes two ints, x and y, and returns an int x+y: No actual addition required! int add(int x, int y); CS 136 Spring 2018 Tutorial 7 19 In the following C code, the assignment operator appears only once: bool nisfive = (n == 5); C This has to be harder than it looks but I m not seeing the trick. CS 136 Spring 2018 Tutorial 7 20 In the following C code, the assignment operator appears only once: bool nisfive = (n == 5); B *False. C *This has to be harder than it looks but I m not seeing the trick. The code above uses = for initializaiton, NOT assignment. They are very slightly different (e.g. some struct-related notation can only be used during initialization, and not assignment). CS 136 Spring 2018 Tutorial 7 21

Coding Question Write the C function pyramid(int n); that prints a pyramid of numbers with n lines. You may assume n is an odd integer in the range [3-99]. Use the printf formatter %3d to print out each integer. pyramid(7) prints the following: 1 2 3 3 4 5 4 5 6 7 3 4 5 2 3 1 CS 136 Spring 2018 Tutorial 7 22 Coding Question General approach: Need nested for loops / while loops. One set of loops to count from row 1 to n/2 + 1, one set to count back down from row n/2 to 1. CS 136 Spring 2018 Tutorial 7 23 Coding Question void pyramid(int n) { for (int i=1; i<=n/2+1; ++i) { for (int j=i; j<=2*i-1; ++j) { printf("%3d",j); printf("\n"); for (int i=n/2; i>0; --i) { for (int j=i; j<=2*i-1; ++j) { printf("%3d",j); printf("\n"); CS 136 Spring 2018 Tutorial 7 24

Stack Trace Draw the call stack immediately after In exchange: is printed. For pointers, draw an arrow to the variable they point at. CS 136 Spring 2018 Tutorial 7 25 Stack Trace 1 void exchange(int *pa, int* pb) { 2 int temp; 3 temp = *pa; 4 *pa = *pb; 5 *pb = temp; 6 printf("in exchange: "); 7 printf("a = %d, b = %d\n", *pa, *pb); 8 9 10 int main(void) { 11 int a, b; 12 a = 5; 13 b = 7; 14 printf("in main: "); 15 printf("a = %d, b = %d\n", a, b); 16 exchange(&a, &b); 17 printf("a = %d, b = %d\n", a, b); 18 CS 136 Spring 2018 Tutorial 7 26 Stack Trace exchange: pa: [arrow pointing to a] pb: [arrow pointing to b] temp: 5 return addr: main : 16 ========== main: a: 7 b: 5 return addr: OS CS 136 Spring 2018 Tutorial 7 27