Chapter 6: Data Types and Pointers Flashcards

(14 cards)

1
Q

What is a descriptor?

A

A descriptor is the collection of attributes of a variable. In implementation, it is an area of memory that stores those attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the advantages and disadvantages of decimal data types?

A

Advantages: They can precisely store decimal values within a restricted range
Disadvantages: Their range of values is restricted because no exponents are allowed and their storage representation is mildly wasteful.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the design issues for character string types?

A

The two most important design issues are whether strings should be a primitive type or a special kind of character array, and whether they should have static or dynamic length.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the three string length options.

A

Static length: The length is set when the string is created and fixed.
Limited dynamic length: Strings can vary in length up to a declared fixed maximum.
Dynamic length: Strings can vary in length with no maximum.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define ordinal, enumeration, and subrange types.

A

Ordinal type: A type where the range of possible values can be easily associated with the set of positive integers.
Enumeration type: An ordinal type where all possible values are named constants provided in the definition.
Subrange type: A contiguous subsequence of an ordinal type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In what ways are the user-defined enumeration types of C# more reliable than those of C++?

A

In C#, enumeration types are never coerced to integer, whereas C++ allows them to be used as integers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the design issues for pointer types?

A

Issues include
- the scope/lifetime of the pointer
- lifetime of the heap variable
- type restrictions
- use for indirect addressing vs. dynamic management
- support for reference types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the two common problems with pointers?

A

Dangling pointers (pointing to deallocated variables) and lost heap-dynamic variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why are the pointers of most languages restricted to pointing at a single type variable?

A

It is required for type checking and for pointer arithmetic (so the system knows how to scale the address index).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a C++ reference type, and what is its common use?

A

It is a constant pointer that is always implicitly dereferenced, commonly used for formal parameters in function definitions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why are reference variables in C++ better than pointers for formal parameters?

A

They allow two-way communication like pointers but are implicitly dereferenced, making code more readable and safer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What advantages do Java and C# reference type variables have over the pointers in other languages?

A

They provide the flexibility of pointers without the dangers of dangling pointers (due to implicit deallocation).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe the lazy and eager approaches to reclaiming garbage.

A

Eager: Reclamation is incremental and happens when inaccessible cells are created.
Lazy: Reclamation occurs only when the list of available space becomes empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why wouldn’t arithmetic on Java and C# references make sense?

A

Because references refer to objects rather than memory addresses, so address arithmetic is not sensible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly