Programming Language Concepts CMPSC 461, FALL 2018 Midterm #2 Solutions
Programming Language Concepts CMPSC 461, FALL 2018 Midterm #2 Solution P# Possible Score 1 8 2 10 3 16 4 8 5 24 6 16 7 10 8 8 Bonus 10 Total 110 This exam is closed book, closed notes. You may not use any additional materials during the exam. All electronic devices must be put away. You may have nothing on your desk except this exam and writing instruments. The exam consists of 8 questions and 1 bonus question on 5 pages, totaling 100 points + 10 bonus points. Read each question carefully and use your time judiciously. The problems are not ordered by their difficulty. Problem 1 [8pt] For each of the following Scheme programs, circle all x’s that refer to (i.e., are in the scope of) the definition of x at the SECOND LINE. You don’t need to circle anything if no such x exists. Solution: (let ((x 1)) (let ((x 2) (y x)) (+ x y)) (let ((x 3)) (let* ((x 4) (y x )) (+ x y))) Problem 2 [10pt] Consider the following C++ program: int *a, *b; void f() { int c=5; a = new int(3); b = &c; } void g () { } int main() { f(); printf("%d,%d,", *a, *b); g(); printf("%d,%dn", *a, *b); delete a; } 1. (4pt) What is the storage allocation (static/stack/heap) for the integers that a and b points to in function f (before f returns)? Solution: Variable a points to a heap allocated integer variable b points to a stack allocated integer 2. (6pt) Here are the outputs of two separate executions of the program: (first run) 3, 5, 3, 32537 (second run) 3, 5,
Written for
Document information
- Uploaded on
- September 25, 2023
- Number of pages
- 6
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
programming language concepts cmpsc 461 fall 2018
Also available in package deal