Chapter 6 Flashcards

1
Q

What does a data type define?

A

Collection of data objects with a range of value and how they are stored in memory.

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

What does an object represent?

A

The instance of a programmer-defined type

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

What is another name for a programmer-defined type?

A

Abstract data type

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

Do all languages provide primitive data type?

A

Almost all of them

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

What is special about Integers?

A

It is an exact reflection of the hardware therefore mapping is trivial

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

How many different integer types are there?

A

May be as many as eight

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

What are the advantages of unsigned integers?

A

It cant go below 0. So you can store a lot more data into the field

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

Do Floating points model real numbers?

A

Yes but only as approximations

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

What are the 2 floating point types?

A

float and double

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

What is the standard for floating points?

A

IEEE Floating-Point Standard 754

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

How many bits does double and float use?

A

double = 64 bits
float = 32 bits
for both 1 bit = signed bit

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

in complex data types, what makes up each value?

A

a real part and an imaginary part (7 + 3j where 7 = real and 3 = imaginary

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

Whats the advantages and DisAdv of decimals

A

Adv : accuracy
DisAdv : waste memory and limited range

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

Why is an advantage of boolean values readability?

A

Simplicity and clear representation

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

How is the primitive data type character stored?

A

numeric codings with most common being ASCII

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

What are the different types of character encodings of primitive data types?

A

ASCII, UCS-2 (16 bit),32-bit Unicode(UCS-4)

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

How are lists represented and what do they hold?

A

ordered sequence of (often) heterogeneous values
Typically represented as a linked list

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

How does lists look like in F#?

A

[1;2;3]

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

What does F# list functions have in common with Scheme?

A

List.head [1;2;3] is equal to car (only returns the 1st element = 1)
List.tail [1;2;3] is equal to cdr in scheme (returns the rest of the list besides the head = [2;3]

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

Are Python lists mutable and what does it mean?

A

Yes. allows [3, 5.8 ,”grape”]

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

How do you delete list elements in Python?

A

del myList[1]

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

How does list comprehensions look like in Python?

A

list = [x ** 2 for x in range(12) if x % 3 == 0]

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

Where is Type theory studied in?

A

Math, Logic, CS, Philosophy

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

What is a union?

A

A type whose variables can store values of different types at different times during execution

25
Q

How many values can be assigned to a union at once?

A

1

26
Q

What are union types used for?

A

Representing Values with Multiple Possibilities

27
Q

What is the difference between Discriminated vs Free Unions

A

Disc = type checking, higher type safety, runtime errors less likely, clearer readability.

free = no type checking, lower type safety, runtime errors more likely, less clear readability

28
Q

union example in C

A

union flexType{
int intEl;
float floatEl;
};

union flexType u1;
u1.intEl = 12;
u1.floatEl = 22.8;
float x = u1.floatEl;
int y = u1.intEl;

29
Q

Example of Discriminant

A

type Shape is (Circle, Triangle, Rectangle);
type Colors is (Red, Green, Blue);
type Figure (Form: Shape) is record
Filled: Boolean;
Color: Colors;
case Form is
when Circle => Diameter: Float;
when Triangle =>
Leftside, Rightside: Integer;
Angle: Float;
when Rectangle => Side1, Side2: Integer;
end case;
end record;

“Form” is the discriminant

30
Q

Why are free unions unsafe?

A

They do not allow type checking

31
Q

Are Ada’s discrimination unions safe?

A

Yes

32
Q

What are pointer type variables?

A

memory addresses that reference a memory
(nil/null = doesnt refer to a memory cell)

33
Q

What are the 2 uses of pointers?

A

power of indirect addressing
manage dynamic memory

34
Q

What is the scope and lifetime of a pointer?

A

Scope = if declared inside function == only accessible in that function. if declared globally == anywhere

lifetime = until memory location it is pointing to isnt valid anymore

35
Q

What is the lifetime of a heap-dynamic variable?

A

Until the user deletes it, otherwise it will result in memory leaks

declared using “new” in c++

36
Q

Are pointers restricted as to the type of value to which they can point?

A

Yes. For type safety and memory management

37
Q

Are pointers used for dynamic storage management, indirect addressing, or both?

A

Both

38
Q

Should the language support pointer types, reference types, or both?

A

Depends. If type safety needed = reference types

39
Q

What are the 2 fundamental operations for pointers?

A

Assignment and dereferencing
int *p = &val;
j = *ptr <- deref

40
Q

What is the problem with pointers?

A

Dangling pointers (seg-faults/memory corruption)
Lost heap-dynamic variable (allocated heap-dynamic variable that is no longer accessible = memory leaks)

41
Q

What are reference type?

A

Similar to pointers but no pointer arithmetic allowed

42
Q

Is reference types or pointers safer?

A

Reference types

43
Q

What is the main purpose of reference types?

A

For parameters
void f(int &p){…}

44
Q

How does Java extend C++ reference variables?

A

Allows them to replace pointers entirely
references can refer only to object and not primitives

45
Q

What need to be done on pointers if they are used for dynamic storage management?

A

manual heap management is necessary

46
Q

Why cant pointers and references not be avoided?

A

need them for dynamic data structures

47
Q

What is type checking?

A

ensuring operands of an operator are of compatible types

48
Q

What is a compatible type?

A

Type that is either legal for the operator or is allowed under language rules to be converted by compiler

49
Q

What is a type error?

A

Application of operator to an operand of inappropriate type

50
Q

If all type bindings are static can nearly all type checking be static and why?

A

Yes. It tells the compiler the types upfront

51
Q

What is the Adv of a strongly typed language?

A

Detects all variable misuses causing type errors

52
Q

Out of the following languages which are strongly typed? C C++ Java C# ML and F#?

A

Java C# ML and F# with ML and F# being very strongly typed

53
Q

What are coercion and what does it do to typing

A

converts operands to same type and it causes type weakening since it can cause accidental type mismatches go undetected

54
Q

Which languages use coercions?

A

C++ Ada and Java

55
Q

What is type equivalence?

A

It defines when operands of 2 types can be substitutable with no coercion

56
Q

When are 2 variable name type equivalent?

A

Same declaration or declarations that use the same type name

57
Q

When are 2 variable structure type equivalent?

A

If their types have identical structures

58
Q

What are the 2 branches of type theory?

A

Practical (data types in commercial languages)
Abstract (typed lambda calculus and of interest only to theoretical computer scientists)

59
Q

What is a type system?

A

A set of types and rules that govern type use in programs