Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What common data types are represented in almost every language? How are thes

ID: 3548905 • Letter: 1

Question

1.      What common data types are represented in almost every language? How are these declared in C++?

2.      What are the arguments for and against representing Boolean values as single bits in memory?

3.      Answer the following:

a.       Describe a use for string pattern matching not listed in your text.

b.      What are the advantages and disadvantages to having dynamic length strings?

4.      Describe how enumeration types and subrange types can enhance readability and reliability.

5.      Differentiate clearly between static, fixed stack-dynamic, stack-dynamic and heap-dynamic arrays.

6.      Consider the following pseudocode array declaration:

X: array [1-5] [1-5] [1-5] of integer;

Assume integers require two bytes of storage and that the array begins at location 10000.  What is address of X[2][3][4], assuming row-major order?  What is the address assuming column-major order?

7.      Consider the following pseudocode:

aggregateType valuePack is

               f: float;

               i: integer;

            end

Assume that floats take four bytes and integers two.  If valuePack is a record, how many bytes does a valuePack require? If valuePack is a union, how many bytes does it require?  Explain.

8.      What is a dangling reference, and how can it lead to program crashes?

9.      Create an example in C++ that causes a memory leak.

10.  Compare the tombstones and locks-and-keys methods of avoiding dangling pointers, from the points of view of safety and implementation cost.

Explanation / Answer

(2) For: Using a single bit instead of an entire byte will conserve memory

Against: Processors to have addresses for single bits. So up to 8 Booleans values can be combined

into a single byte, which means bit-wise arithmetic to separate the separate values. Although this


conserves memory, it takes more time (CPU time) to deal with.


(4) Enumeration Types:

. All possible values, which are named

constants, are provided in the definition

. C# example

enum days {mon, tue, wed, thu, fri, sat, sun};

. Design issues