100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CMPSC 461: Programming Language Concepts Assignment 6 Solution

Rating
-
Sold
-
Pages
3
Grade
A+
Uploaded on
25-09-2023
Written in
2023/2024

CMPSC 461: Programming Language Concepts Assignment 6 Solution Problem 1 [6pt] Assume that integers are stored using one byte in memory. What are the binaries for 8 and -10 in two’s complement format? What is the result of (8-10) in two’s complement format? Solution: binary for 8: binary for -10: result of (8-10): Problem 2 [10pt] Consider the following C declaration: union U1 {int a; float b;}; union U2 {char a; double b;}; struct S { union U1 u1; union U2 u2; } s; Assume that the machine has 1-byte characters, 4-byte integers, 8-byte floating numbers, and 16-byte double-precision floating numbers. Assume the compiler does not reorder the fields, and it leaves no holes in the memory layout. a) (4pt) How many bytes does s occupy? Solution: s occupies max(4,8)+max(1,16)=24 bytes. b) (6pt) If the memory address of s starts from 1000, what are the start addresses of s.u1.b and s.u2.b? Solution: The start address of s.u1.b is 1000; the start address of s.u2.b is 1008. Problem 3 [8pt] In a programming language, there are multiple times that the size of an array can be determined, such as a) Static/Fixed - the dimensions of the array are known at compile time, and they are fixed b) Dynamic/Fixed - the dimensions are not known until storage is allocated for an array, but then are fixed For each of these, describe an appropriate representation and allocation strategy (stack/heap). Describe how bounds checking would be supported. You should consider both one and multi- dimensional arrays. Solution: (This is an open question. We only show one possible solution) a) Since the array size is available at compile time, the compiler can allocate continuous space on the stack. Multi-dimensional arrays can either follow row-major or column-major layout. Since the size of the array

Show more Read less








Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
September 25, 2023
Number of pages
3
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ExamsConnoisseur Self
View profile
Follow You need to be logged in order to follow users or courses
Sold
566
Member since
2 year
Number of followers
343
Documents
1497
Last sold
1 week ago

4.3

67 reviews

5
40
4
11
3
12
2
1
1
3

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions