Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 434 Exam 3: Problem Solutions and Additional Questions, Exams of Computer Science

Solutions to problems 1-3 from cs 434 exam 3, as well as additional questions for university students related to recursion, stack frames, and c++ class objects. The document also covers topics like tam programming, runtime stack analysis, and two-dimensional arrays.

Typology: Exams

Pre 2010

Uploaded on 09/17/2009

koofers-user-8cx
koofers-user-8cx 🇺🇸

10 documents

1 / 8

Toggle sidebar

Related documents


Partial preview of the text

Download CS 434 Exam 3: Problem Solutions and Additional Questions and more Exams Computer Science in PDF only on Docsity! CS 434 Exam 3 Name ________________________ Spring 2004 This exam has 7 problems, and each problem is worth at least 15 points, so there is some built-in extra credit. 1. Convert this Triangle program to an equivalent TAM program. let var a:Integer; var b:Integer; var c:Integer in begin getint(var a); getint(var b); c:=(a+7)*(b-6); putint(c*c) end } 4. Consider again the C++ program from problem 3. For each of the nine classes, draw the class object (method table). 5. Consider the C++ declaration below. Assume a byte-addressable machine such that each double uses 8 bytes, each int uses 4 bytes, each char uses 1 byte, and each float uses 4 bytes. Also assume that s[0][0].d[0] is at location 0, and two-dimensional arrays are stored in row-major order. struct {double d[3]; int i; char c[8]; float f;} s[100][10]; a. Determine the total size in bytes for variable s. b. Determine the location of s[10][0].c[4] c. Determine the location of s[50][5].d[1] 6. Consider the C++ program below. void f(int*& a, int*& b) { if (*a > *b) a=b; else { delete b; b=a; } } void main( ) { int *p, *q, *r; p=q=new int; r=new int; cin >> *q; cin >> *r; if (*r > 0) f(q, r); else f(r, q); cout << *p << endl; cout << *q << endl; cout << *r << endl; } a. Can any sequence of input values cause a memory leak (garbage)? If so, specify such input values, and draw a picture that clearly represents the situation in the heap just before the program ends. b. Can any sequence of input values cause a dangling pointer? If so, specify such input values, and draw a picture that clearly represents the situation in the heap just before the program ends. c. Very briefly state how some programming languages (not C++) prevent both memory leaks and dangling pointers.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved