Chapter 6 - Data Types Flashcards

1
Q

Definition of Data Type

A

defines a collection of data values and a set of pre-defined operations on those values

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

Definition of descriptor

A

the collection of the attributes of a variable

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

Definition of primitive data type

A

data types that are not defined in terms of other types

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

Why do primitive data types need very little non-hardware support for implementation?

A

These types are merely reflections of the hardware itself

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

What does it mean to be “a reflection of the hardware”?

A

that the entity is represented by some physical hardware mechanism

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

The 4 types of integer sizes in Java

A

byte
short = 2 bytes
int = 4 bytes
long = 8 bytes

(all integers in Java are signed)

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

Why are integers a reflection of the hardware?

A

The maximum value that can be represented, depends on the number of physical mechanisms used to define each bit

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

3 Different hardware implementations for signed integers

A

Dumb way = the most significant bit (the left-most one) determines the sign of the number. 1 implies a negative number and 0 implies a positive number

One’s Complement = The negation of a given number is obtained by flipping all the bits of that number.

Two’s Complement = the negation of a number is obtained by flipping all the bits and then adding one

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

Definition of Floating-point number data type

A

a primitive data type modeling real numbers (not just integers)

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

What is the size of a regular floating point number? How are the bits distributed?

A

4 bytes or 32 bits

sign bit = 1 bit
exponent = 8 bits
fraction or mantissa = 23 bits

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

Definition of double data type

A

A double precision floating point number

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

What is the size of a double data type? how are the bits distributed?

A

8 bytes or 64 bits

sign bit = 1 bit
exponent = 8 bits
fraction or mantissa = 53 bits

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

What is the floating point number exponent value and how is it represented?

A

The exponent refers to the exponent value of the floating point number in scientific notation

Simply add 127 to the value of the exponent and express that result in binary (doesn’t change for negative exponents).

ex) exponent = 5, result = 5 + 127 = 132, bin(132) = 1000010 (27 + 22 = 132)
exponent of 5 = 1000010

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

What is the floating point number fraction value and how is it represented?

A

Each digit after the decimal point represents a negative power of 2. Decimal values are approximated by combining these negative powers of 2

  1. 1 = 2**-1 = 0.5 (in decimal)
  2. 001 = 2**-2 = 0.25
  3. 0001 = 2**-3 = 0.125

The number in front of the decimal point is expressed normally in binary

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

How to express the sign of a floating point number

A

The sign bit represents the sign of the mantissa!

1 = negative
0 = positive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Definition of decimal data type

A

store a fixed number of decimal digits with the decimal point at a fixed position in the value

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

What common PLs have decimal data types?

A

COBOL
C#
F#

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

What is the main advantage of using decimal numbers instead of floating point numbers?

A

Decimal numbers are able to store decimal values exactly within a limited range

Floating point numbers can only approximate decimal values (remember that they approximate decimal values by using combinations of negative powers of 2, which makes it impossible to precisely store certain values)

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

What are the disadvantages of using decimal numbers instead of floating point numbers?

A

for decimal numbers:

  • the range of values that can be expressed is limited
  • their representation in memory is slightly wasteful
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Definition of a nibble

A

4 bits or half of a byte

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

What does BCD stand for? What does it mean?

A

binary coded decimal

Meaning that each digit (0-9) and the sign(+/-), is represented by a nibble (4 bits)

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

How are the digits of a decimal number represented in binary?

A

The leftmost digit of the decimal number is the leftmost nibble in the binary representation

The digits 0-9 are represented by their normal 4-bit binary values (ex. 9 = 1001)

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

How is the sign of a decimal number represented in binary?

A

The sign is the rightmost nibble
+ sign represented by: 1100
- sign represented by: 1101

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

Definition of boolean data type

A

a data type with 2 allowed values true or false

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

What is the size of a normal boolean data type?

A

1 byte

It can theoretically be represented by 1 bit, however, this data type is typically stored in the smallest efficiently addressable cell of memory (typically 1 byte)

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

Which PL was first to include the boolean data type?

A

ALGOL 60

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

How is character data represented in memory?

A

with some numeric coding

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

ASCII vs Unicode

A

ASCII - an 8-bit numeric coding for characters. Can represent 128 characters (0-127)

Unicode - a 16-bit numeric coding for characters. The first 128 characters are identical to ASCII

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

Definition of character string type

A

a data type consisting of sequences of characters

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

Two most prominent representations of Strings

A

implemented as a (hardware) primitive type or as an array of single characters

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

2 main design issues pertaining to Strings

A

1) should it be implemented as some kind of character array or as a primitive type?
2) should they have static or dynamic length

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

Definition of Static length string

A

the length is set when the string is created.

The length can only be adjusted by creating a new string variable (or reference)

33
Q

5 PLs that use static length strings

A
python
java
C++
Ruby
C#
34
Q

Definition of Limited dynamic length string

A

allows the string to be of varying length up to a declared and fixed maximum set by the variables definition

35
Q

2 PLs with limited dynamic length strings

A

C

C++ (using C-style strings)

36
Q

Definition of dynamic length strings

A

allows strings to be of varying length with NO maximum

37
Q

3 PLs with dynamic length strings

A

Javascript
Perl
C++ STL

38
Q

What 3 attributes need to be maintained in a static length string descriptor

A

name of the type
length of the type in characters
address of the first character

39
Q

What 2 additional attributes need to be maintained for limited dynamic length strings? Are there alternatives to these attributes?

A

a run-time descriptor needs:

1) fixed max length
2) the current length

C doesn’t use a run-time descriptor but instead has a null character as the last character of every string denoting the end of it

40
Q

3 storage schemes for dynamic length strings

A
  • stored as a linked list
  • stored as an array of pointers of individual characters
  • store all strings in adjacent memory (dedicated area of memory to strings)
41
Q

1 pro and 1 con for storing dynamic length strings as a linked list

A

Pro = highly growable

Con = complicated operations

42
Q

1 pro and 1 con for storing dynamic length strings as an array of pointers to characters

A

pro = fast

con = bulky

43
Q

1 pro and 1 con for storing dynamic length strings in adjacent memory

A

pro = string ops are faster

con = allocation is slower

44
Q

Definition of ordinal type

A

a data type in which variables take one of a finite number of values (these possible values are typically represented by a set of positive integers)

int, char boolean, array subscripts are all ordinal types

45
Q

What are the 2 user-defined ordinal types commonly supported by PLs

A

enumeration

subrange

46
Q

Definition of enumeration type

A

a type that defines a collection of named constants called enumeration constants

47
Q

3 Design issues for enumeration types

A
  • can a given enumeration constant appear in more than one type?
  • are the constants coerced to int?
  • are other types coerced to the enumerated type
48
Q

Definition of array data type

A

an aggregate of homogeneous data elements in which an individual element is identified by its position in the aggregate relative to the first element

49
Q

7 design issues pertaining to arrays

A

1) what types are legal for subscripts
2) are subscripting expressions in element references range checked? (is it in the range of the array)
3) when are subscript ranges bound
4) when does allocation take place
5) what is the maximum number of subscripts
6) can array objects be initialized
7) are slices allowed

50
Q

PLs that enforce subscript range checking

A

Ada
Java
C#

51
Q

5 categories of arrays

A
Static
Fixed stack dynamic
Stack dynamic
Fixed heap dynamic
heap dynamic
52
Q

What 2 characteristics define the 5 different categories of arrays

A

subscript binding
binding to storage

(remember binding is the association of some attribute to some variable)

53
Q

Definition of a static array and its main advantage

A

the range of subscripts and storage bindings are static

Adv: execution efficiency (no allocation or deallocation)

54
Q

Definition of a fixed stack dynamic array and its main advantage

A

the range of subscripts bound statically but storage bound at declaration elaboration time

Adv: space efficiency

55
Q

Definition of a stack dynamic array and its main advantage

A

range and storage are dynamic (at declaration elaboration time), but then are fixed for the remaining lifetime of the variable

Adv: flexibility bc size need not be known until use

56
Q

Definition of a fixed heap dynamic array and its main advantage

A

similar to stack dynamic arrays except for the subscript ranges and storage bindings are not done until the program makes use of them (not declaration elaboration time)

Adv: flexibility

57
Q

Definition of a heap dynamic array and its main advantage

A

subscript ranges and storages bindings are dynamic and not fixed

Adv: flexibility, especially in that arrays can shrink and grow

58
Q

Definition of array operation

A

an operation that operates on the array as a unit

59
Q

Common PLs that support array operations

A

Ada
FORTRAN 95+
APL (Array Processing Language)

60
Q

How are arrays represented in memory?

A

a sequence of adjacent memory cells

61
Q

How to calculate the address of the kth element of an array?

A

address_first_element + (k - lower_bound_subscript) * sizeof_element

62
Q

Calculate address of element in the ith column and jth row in 2D array

A

address_first_element + (j - row_lower_bound)sizeof_row + (i - column_lower_bound)sizeof_element

63
Q

Definition of associative array

A

an unordered collection of data elements that are indexed by an equal number of values called keys

AKA a hash table

64
Q

definition of a record type

A

a possibly heterogeneous aggregate of data elements which the individual elements are defined by names

65
Q

3 design issues with records

A

how are they referenced

what operations are defined

are elliptical references allowed

66
Q

Definition of elliptical reference

A

the ability to reference a data member or method without an explicit reference the record/class (don’t need to use the dot operator)

67
Q

PLs allowing elliptical references

A

COBOL
Ada
Pascal

68
Q

How are records organized in memory?

A

All record data stored as contiguous block in memory

individual fields are accessible through an offset value (this is because the different members/methods have different sizes)

69
Q

definition of union type

A

a data type that allows for the storage of different data types in the same memory location

each of the data types is members and only one may have a value at a time

70
Q

Discriminated vs Free unions

A
discriminated = includes a tag for type checking
free = no type checking at all
71
Q

Definition of pointer type

A

a type which value is a memory address to some location holding data

72
Q

2 primary uses for pointers

A

indirect addressing

access to dynamic storage

73
Q

5 design issues with pointers

A

what is the scope and lifetime of them

what is the lifetime of heap dynamic variables

are they restricted to point to a particular type

are pointers used one or both of the two primary uses

should a language support both pointer types and reference types?

74
Q

What are the 2 pointer operations

A

assignment ( int* p = new int, p = &x)

dereference (x = *ptr, p -> age)

75
Q

definition of a dangling pointer

A

a pointer that points to a heap dynamic variable that has been deallocated

76
Q

definition of a memory leak

A

the existence of a heap dynamic variable that is no longer referenced by any program pointer

77
Q

5 characteristics of pointers in C/C++

A

used for dynamic storage and addressing

explicit dereferencing

can do address arithmetic

void* = can point to any type but cannot be dereferenced

can use void* to pass functions as parameters to other functions

78
Q

definition of reference type

A

similar in nature to a pointer except that it refers to an object or value in memory instead of an address

AKA no address arithmetic