COMP 524 Spring 2018 Midterm Thursday, March 1

Similar documents
ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 19 November 2014

CS 415 Midterm Exam Spring SOLUTION

COMP 101 Spring 2017 EXAM 2 2 March 2017

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

CS 415 Midterm Exam Spring 2002

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

ECE 2035 Programming HW/SW Systems Spring problems, 5 pages Exam Three 8 April Your Name (please print clearly)

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

ECE 2035 Programming HW/SW Systems Fall problems, 4 pages Exam Three 14 November Your Name (please PRINT clearly) Signed.

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

Memory and C++ Pointers

ENEE 150: Intermediate Programming Concepts for Engineers Spring 2018 Handout #27. Midterm #2 Review

Class Information ANNOUCEMENTS

CPSC 3740 Programming Languages University of Lethbridge. Data Types

15-122: Principles of Imperative Computation, Spring Written Homework 12. Due: Sunday 15 th April, 2018 by 10pm. Name: Andrew ID: Section:

Please submit your request directly to Noha Sinno

a data type is Types

Creating a String Data Type in C

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 18 November 2015

CSE351 Winter 2016, Final Examination March 16, 2016

COMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015

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

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Separate Compilation Model

Midterm II CS164, Spring 2006

CS3360 Design and Implementation of Programming Languages Final Exam May 16, pm to 12:45pm (2 hour and 40 minutes) NAME:

CMPT 125: Practice Midterm Answer Key

Review! Lecture 5 C Memory Management !

CS61C : Machine Structures

In Java we have the keyword null, which is the value of an uninitialized reference type

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

Pointer Casts and Data Accesses

Variables, Memory and Pointers

CSCI Compiler Design

Writing Functions in C

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

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

Final Exam. COMP Summer I June 26, points

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

COMP 101 Spring 2017 Final Exam Section 1 Friday, May 5

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

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 9. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

Today's Topics. CISC 458 Winter J.R. Cordy

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

Introduction to Programming Using Java (98-388)

McGill University School of Computer Science COMP-202A Introduction to Computing 1

CSE-160 (Winter 2017, Kesden) Practice Midterm Exam. volatile int count = 0; // volatile just keeps count in mem vs register

What goes inside when you declare a variable?

Lesson 8: Linked List Deque

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Kurt Schmidt. October 30, 2018

CS 314 Principles of Programming Languages

CSE 333 Midterm Exam 5/9/14 Sample Solution

CPSC 213, Summer 2017, Term 2 Midterm Exam Solution Date: July 27, 2017; Instructor: Anthony Estey

Comp 311: Sample Midterm Examination

CSE 131S Introduction to Computer Science Summer SON Exam III

Functions in C. Lecture Topics. Lecture materials. Homework. Machine problem. Announcements. ECE 190 Lecture 16 March 9, 2011

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

EECE.4810/EECE.5730: Operating Systems Spring Midterm Exam March 8, Name: Section: EECE.4810 (undergraduate) EECE.

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

CS 3360 Design and Implementation of Programming Languages. Exam 1

Compilers. Computer Science 431

CMSC 330: Organization of Programming Languages

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

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.

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Memory and Addresses. Pointers in C. Memory is just a sequence of byte-sized storage devices.

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 314 Principles of Programming Languages. Lecture 11

Introduction to Computer Systems. Exam 2. April 10, Notes and calculators are permitted, but not computers.

Homework I - Solution

CS 314 Principles of Programming Languages. Lecture 13

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Computer Science Foundation Exam

CSE 131S Introduction to Computer Science Summer SON Exam I

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

Structure of Programming Languages Lecture 10

COMP1917 Computing 1 Written Exam Sample Questions

CSE 341, Spring 2011, Final Examination 9 June Please do not turn the page until everyone is ready.

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

Operational Semantics. One-Slide Summary. Lecture Outline

CSc 520 final exam Wednesday 13 December 2000 TIME = 2 hours

04-19 Discussion Notes

CS 1713 Introduction to Programming II

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

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

However, in C we can group related variables together into something called a struct.

Programming Languages

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n

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

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

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, SPRING 2013

Transcription:

Name PID COMP 524 Spring 2018 Midterm Thursday, March 1 This exam is open note, open book and open computer. It is not open people. You are to submit this exam through gradescope. Resubmissions have been enabled. Download the fillable pdf and add your name and PID. Save the file and then make sure that the save worked properly. Remember to save your work often and confirm that it is being saved. If you are unable to open the pdf, use a paper test. If you do that, you are responsible for scanning it and uploading the scanned pdf to gradescope before 6 pm. The test is based on 100 points. Questions have different values. You should read the entire exam before starting to answer questions. The test is designed for 60 minutes; you have 75 minutes to complete it. By submitting this exam, you are pledging that you have neither given nor received unauthorized help.

Question 1 (20 points) What would the following program output if the language is lexically (statically) scoped? What would it output if it is dynamically scoped? You must provide traces with the start and end of each function, the value of x at each point, and the return values of functions in order to get credit. If a function does not return a value, say so. Sample trace (clearly not correct or complete): x = 72 Enter f x = 54 Enter g x = 16 x = 17 Return 46 Resume f Return 22 Print 87 Lexical (Static) Scoping var x : int = 0 function f() { var x : int = 3 return g() function g() { x++ h() return x function h() { x++ print f() Dynamic Scoping

Question 2 (10 points) type T = int[4] type V = int[4] type S = T var a: T = [1, 2, 3, 4] var b: V = a var c: S = b var d = [1, 2, 3, 4] Given that the above is a valid snippet and all of the variables listed would compare to be equal, what kind of equivalence does this language support (structural or name)? Explain your answer. If the other type of equivalence were used, which variables would be considered equivalent? Does this language support type aliasing? Explain your answer and indicate what would be different if the opposite were true. That is, would something in the snippet be invalid or would some of the equivalences change?

Question 3 (30 points) struct Node *head = NULL; struct Node { int value; struct Node *next; struct Node *prev; ; void delete(struct Node *node, int key) { while (node!= NULL && node->value!= key) { node = node->next; if (node!= NULL) { if (node->prev!= NULL) { node->prev->next = node->next; else { head = node->next; int main() { int i = 1, j = 2, k = 3; struct Node *a = malloc(sizeof(struct Node)); struct Node *b = malloc(sizeof(struct Node)); struct Node *c = malloc(sizeof(struct Node)); a->value = i; b->value = j; c->value = k; Given the program to the left in a C-like language (i.e., one that supports pointers and allocation and freeing), identify which variables are located in the stack, which are in the heap, and which in static storage. You can assume that main behaves like any other function. You can assume that the free function frees the struct that it is pointing to. Variable locations i j k a b c head Does the program contain any memory leaks? If so, suggest how you might fix them. You do not need to write the code just describe what needs to be done head = a; head->prev = NULL; a->next = b; b->next = c; b->prev = a; c->next = NULL; c->prev = b; delete(head, 2); free(head); Notation: If T is a structure with an element e, T *v v is a pointer to type T *v refers to the actual value v->t same as (*v).

Question 4 (10 points) Suppose a language supports primitive values that can be null. Given an example of how this could be useful to the user of the language (users of the language include both writers and readers). How might this affect the implementation of primitive values in this language? Can you identify any potential negatives with supporting null primitives?

Question 5 (15 points) Type checking can be done either dynamically or statically. Explain the benefits and costs of dynamic type checking. Identify specific features that require dynamic type checking (e.g., data types that need it, language choices such as required declarations, different types of binding)

Question 6 (15 points) Discuss the pros and cons of automatic type conversion vs required casting. Which is more efficient for the user of the language? Which is more efficient for the compiler? Does it matter if the language does dynamic or static type checking? Describe the problems that can occur when automatic type conversion and polymorphism both exist in a language. Are there only specific types of polymorphism that cause these problems? Give an example of polymorphism that should not be affected by automatic conversion.