Chapter 6 Flashcards

(59 cards)

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
How many values can be assigned to a union at once?
1
26
What are union types used for?
Representing Values with Multiple Possibilities
27
What is the difference between Discriminated vs Free Unions
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
union example in C
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
Example of Discriminant
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
Why are free unions unsafe?
They do not allow type checking
31
Are Ada's discrimination unions safe?
Yes
32
What are pointer type variables?
memory addresses that reference a memory (nil/null = doesnt refer to a memory cell)
33
What are the 2 uses of pointers?
power of indirect addressing manage dynamic memory
34
What is the scope and lifetime of a pointer?
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
What is the lifetime of a heap-dynamic variable?
Until the user deletes it, otherwise it will result in memory leaks declared using "new" in c++
36
Are pointers restricted as to the type of value to which they can point?
Yes. For type safety and memory management
37
Are pointers used for dynamic storage management, indirect addressing, or both?
Both
38
Should the language support pointer types, reference types, or both?
Depends. If type safety needed = reference types
39
What are the 2 fundamental operations for pointers?
Assignment and dereferencing int *p = &val; j = *ptr <- deref
40
What is the problem with pointers?
Dangling pointers (seg-faults/memory corruption) Lost heap-dynamic variable (allocated heap-dynamic variable that is no longer accessible = memory leaks)
41
What are reference type?
Similar to pointers but no pointer arithmetic allowed
42
Is reference types or pointers safer?
Reference types
43
What is the main purpose of reference types?
For parameters void f(int &p){...}
44
How does Java extend C++ reference variables?
Allows them to replace pointers entirely references can refer only to object and not primitives
45
What need to be done on pointers if they are used for dynamic storage management?
manual heap management is necessary
46
Why cant pointers and references not be avoided?
need them for dynamic data structures
47
What is type checking?
ensuring operands of an operator are of compatible types
48
What is a compatible type?
Type that is either legal for the operator or is allowed under language rules to be converted by compiler
49
What is a type error?
Application of operator to an operand of inappropriate type
50
If all type bindings are static can nearly all type checking be static and why?
Yes. It tells the compiler the types upfront
51
What is the Adv of a strongly typed language?
Detects all variable misuses causing type errors
52
Out of the following languages which are strongly typed? C C++ Java C# ML and F#?
Java C# ML and F# with ML and F# being very strongly typed
53
What are coercion and what does it do to typing
converts operands to same type and it causes type weakening since it can cause accidental type mismatches go undetected
54
Which languages use coercions?
C++ Ada and Java
55
What is type equivalence?
It defines when operands of 2 types can be substitutable with no coercion
56
When are 2 variable name type equivalent?
Same declaration or declarations that use the same type name
57
When are 2 variable structure type equivalent?
If their types have identical structures
58
What are the 2 branches of type theory?
Practical (data types in commercial languages) Abstract (typed lambda calculus and of interest only to theoretical computer scientists)
59
What is a type system?
A set of types and rules that govern type use in programs