CSE 465 Midterm 2

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/122

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

123 Terms

1
New cards
variable
Is an abstraction of a memory cell
2
New cards
Scope
range of statements over which a variable is visible
3
New cards
Reserved words
a special word of a programming language that cannot be used as a name
4
New cards
static
A binding is ______ if it first occurs before run time begins and remains unchanged throughout the program execution
5
New cards
Dynamic
If the binding first occurs during runtime or can change in the course of the program execution
6
New cards
explicit declaration
is a statement in the program that lists variable names and specifies that they are a particular type
7
New cards
implicit declaration
is a means of associating variables with types through default conventions
8
New cards
implicit declaration
First appearance of a variable name in a program is ______
9
New cards
reference environment of a statement
the set of all names that are visible in the statement
10
New cards
static scope
local variables plus all the visible variables in all the enclosing scopes
11
New cards
dynamic scope
local variables plus all visible variables in all active subprograms
12
New cards
dynamically typed
what type of language is python?
13
New cards
Object oriented
What type of language is C#?
14
New cards
\*
de-reference operator
15
New cards
&
reference operator
16
New cards
pointer type variable
has a range of values that consists of memory addresses and a special value,nil.
17
New cards
the address of
&var reads as
18
New cards
type \*
declares a pointer to an object of the data type type
19
New cards
new type
allocates new object on the heap and returns a pointer to that object
20
New cards
\*var
dereference operator
21
New cards
\*var reads as
the value/data stored at the pointer address
22
New cards
memory leak
memory that is no longer needed is not released
23
New cards
dangling pointer
a pointer that contains the address of a heap-dynamic variable that has been deallocated
24
New cards
5
Let L = \[7,6,5,4,3\]. What does the following return? \n len(L)
25
New cards
4
Let L = \[7,6,5,4,3\]. What does the following return? \n L\[-2\]
26
New cards
\[6, 5, 4\]
Let L = \[7,6,5,4,3\]. What does the following return? \n L\[1:4\]
27
New cards
\[\]
Let L = \[7,6,5,4,3\]. What does the following return? \n L\[1:4:-1\]
28
New cards
\[3, 5\]
Let L = \[7,6,5,4,3\]. What does the following return? \n L\[4:1:-2\]
29
New cards
\[6, 5, 4, 3\]
Let L = \[7,6,5,4,3\]. What does the following return? \n L\[1:7\]
30
New cards
F
T/F: All elements of a list must have the same type.
31
New cards
F
T/F: All variables must be declared prior to use.
32
New cards
T
T/F: -1 is a potentially valid index for a list (i.e., if L is a long-enough list, L\[-1\] would return an element).
33
New cards
T
T/F: Python has an if-elif-else conditional statement.
34
New cards
Case sensitivity \n Special words (reserved or keywords) \n Length \n Special characters
Design issues for names
35
New cards
Variable
An abstraction of a (collection of) memory cell(s)
36
New cards
int \*x = new int; \n (new int represents the nameless variable)
Representation of a nameless variable
37
New cards
T
T/F: A variable's memory address may be different at different times during execution or at different places in a program
38
New cards
Variable Type
Determines the range of values of variables and the set of operations that are defined for values of that type
39
New cards
Variable Value
The contents of the location with which the variable is associated
40
New cards
Its address
What is the l-value of a variable?
41
New cards
Its value
What is the r-value of a variable?
42
New cards
Binding
An association between an entity and an attribute, such as between a variable and its type or value, or between an operation and a symbol
43
New cards
Binding time
The time at which binding takes place
44
New cards
Language design time \n Language implementation time \n Compile time \n Load time \n Runtime
Possible Binding Times
45
New cards
1D \n 2A \n 3B \n 4C \n 5E
MATCH: \n \n 1. Language design time \n 2. Language implementation time \n 3. Compile time \n 4. Load time \n 5. Runtime \n \n A. Binding floating point type to a representation; int to a range of values \n B. Binding a variable to a type in C or Java \n C. Binding a C or C++ static variable to a memory cell \n D. Binding operator symbols to operations (e.g., \* to multiplication) \n E. Binding a nonstatic local variable to a memory cell
46
New cards
Explicit declaration
a program statement used for declaring the types of variables
47
New cards
Dynamic binding
First occurs during execution or can change during execution of the program
48
New cards
Static binding
Occurs before run time and remains unchanged throughout program execution
49
New cards
Implicit declaration
\
a default mechanism for specifying types of variables through default conventions/naming requirements or inferencing, rather than declaration statements
50
New cards
Type inferencing
Use context to determine the type of a variable \n C#: var
51
New cards
Dynamic type binding
Specified through an assignment statement e.g., JavaScript \n l = \[2, 4.33, 6, 8\]; \n l = 17.3; \n A variable's type can change multiple times during program execution
52
New cards
Allocation
Getting a cell from some pool of available cells
53
New cards
Deallocation
Putting a cell back into the pool
54
New cards
Lifetime
The time during which a variable is bound to a particular memory cell
55
New cards
Static Variable
bound to memory cells before execution begins and remains bound to the same memory cell throughout execution, e.g., C and C++ static variables in functions
56
New cards
Static variable advantage
efficiency (direct addressing)
57
New cards
Static variable disadvantage
lack of flexibility (no recursion)
58
New cards
Stack-dynamic variables
storage bindings are created for variables when their declaration statements are elaborated \n a declaration is elaborated when the executable code associated with it is executed
59
New cards
allows recursion; conserves storage
Static-dynamic variable advantage
60
New cards
overhead of allocation and deallocation \n subprograms cannot be history sensitive \n inefficient references (indirect addressing)
Static-dynamic variable disadvantages
61
New cards
Explicit heap-dynamic variables
\
Allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution \n Referenced only through pointers or references, e.g., dynamic objects in C++ (via new and delete), all objects in Java \n \n ex: new int
62
New cards
provides for dynamic storage management
Explicit heap-dynamic variable advantage
63
New cards
inefficient and unreliable
Explicit heap-dynamic variable disadvantage
64
New cards
Implicit heap-dynamic variables
allocation and deallocation caused by assignment statements \n e.g., all strings and arrays in Perl, JS, and PHP
65
New cards
flexibility (generic code)
Implicit heap-dynamic variable advantage
66
New cards
inefficient b/c all attributes are dynamic \n loss of error detection
Implicit heap-dynamic variable disadvantages
67
New cards
Variable scope
The range of statements over which a variable is visible
68
New cards
Local variables
Declared in that unit
69
New cards
Nonlocal variables
Visible in the unit but not declared there
70
New cards
Global variables
Special category of nonlocal variables
71
New cards
Based on program text \n To connect a name reference to a variable, you or the compiler must find the declaration
Static Scope (Lexical Scope)
72
New cards
Dynamic Scope
Based on calling sequences of program units, not their textual layout (temporal versus spatial) \n \n References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point
73
New cards
Referencing Environments
The set of all names that are visible in a given statement
74
New cards
Python Global Scope
A global variable can be referenced in functions but can be assigned in a function only if it has been declared to be global in the function \n (Similarly for nonlocal variables)
75
New cards
Python with statement
Ensures that file(s) is/are properly closed after the nested block of code, no matter how the nested block exits (e.g., even if exceptions occur)
76
New cards
Python indentation
How blocks of code are defined (i.e., by having the same indentation)
77
New cards
Dynamically (binding of variables to data type happens at runtime)
Python is a _ typed language
78
New cards
Immutable, references
Tuples are _, but they contain object _.
79
New cards
for i in range(n): \n print(i) \n \n for x in myList: \n print(x)
Python for loop template
80
New cards
Object-oriented, C++, Java
C# is an _ language derived from _ and _.
81
New cards
Garbage collection, automatic memory management
C# supports _ and
82
New cards
T, but the support is limited-can only hold the memory address of value types and arrays, not reference types
T/F: C# supports pointers
83
New cards
\*
C# de-reference operator
84
New cards
&
C# reference operator
85
New cards
F, it can contain multiple classes
T/F: A portable executable C# file can only contain one class
86
New cards
namespaces
C# classes are grouped in _, which are NOT related to directories
87
New cards
Capital
C# library methods start with a capital or lowercase letter?
88
New cards
foreach (var x in myArray) \n Console.WriteLine(x)
C# for loop template
89
New cards
Fields
Member variables or methods in a class
90
New cards
Properties
An extension of fields that are accessed using the same syntax using accessors
91
New cards
Indexers
Allow objects of a class to be indexed like an array
92
New cards
var lines = File.ReadAllLines(args\[0\]); \n foreach (var line in lines) { \n Console.WriteLine(line); \n }
C# reading from a file code template
93
New cards
Non-generic collections that can be enumerated (i.e., you can foreach to iterate through its elements)
C# IEnumerable Interface
94
New cards
foreach
Implementing the IEnumerable interface allows use with _ syntax
95
New cards
Ienumerator
For IEnumerable, you must also implement the interface _.
96
New cards
MoveNext()
Enumerator objects are positioned before the first element in the collection and they get advanced to the first element by the first call to _.
97
New cards
Pointers (in C, C++)
Have a range of values that consist of memory addresses and a special value, nil
98
New cards
new (type)
allocates new object on the heap and returns a pointer to that object \n \n ex: \n int\* p; \n p = new int; \n ... \n delete p;
99
New cards
pointers \n \n ex: \n int a\[5\]; is almost equivalent to int\* a; \n int a\[5\]; is equivalent to const int\* a;
Arrays in C++ are implemented as _
100
New cards
Traditional array notation: a\[3\] \n Pointer arithmetic: \*(a + 3)
How can elements of an array be dereferenced?