CS 280 Final Exam Review Slides Concepts

0.0(0)
studied byStudied by 9 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/108

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.

109 Terms

1
New cards

Descriptors

The collection of attributes of a variable

2
New cards

type checking, allocation, and deallocation

What are descriptors used for?

3
New cards

Descriptor of Static Attributes

Type of descriptor required only at compile-time; typically built as part of the symbol table.

4
New cards

Descriptor for Static Attributes

Descriptor type used for compile-time features like static string length and static attributes of arrays

5
New cards

Descriptor of dynamic attributes

Type of descriptor that must be used and maintained by the run-time system.

6
New cards

Descriptor dynamic attributes

Descriptor used at run-time for values like limited dynamic strings.

7
New cards

Row major order

A method of storing multi-dimensional array elements in memory by rows, where elements of each row are stored contiguously.

8
New cards

Column major order

A method where elements of a multi-dimensional array are stored in memory by columns, with each column's elements stored contiguously.

9
New cards

Row Major Order

The formula Location(a[i,j]) = address of a[row_lb,col_lb] + (((i - row_lb) * n) + (j - col_lb)) * element_size is used to compute memory location in this array storage order.

Location(a[i, j]) = base_address + ((row_index × num_columns) + column_index) × element_size

10
New cards

Column Major Order

Storage order for arrays typically used in Fortran.

11
New cards

Row Major Order

Storage order for arrays typically used in most programming languages (e.g., C, Java, Python).

12
New cards

Access function

A mechanism used in array implementation that maps subscript expressions to a memory address.

13
New cards

Access function for memory address of an element in a single-dimensional array

address(list[k]) = address(list) + (k * element_size)

14
New cards

0

In languages like C, C++, and Java, what is the typical lower bound for array indexing?

15
New cards

Simplified version of the access function for 2D arrays assuming 0-based indexing

Location(a[i,j]) = base_address + ((i * n) + j) * element_size

16
New cards

Access function

When no index range checking is performed and all array attributes are static, what is the primary mechanism used to locate elements?

17
New cards

Dangling Pointers and Lost Heap Dynamic Variables

What are the two common problems of pointers?

18
New cards

Dangling pointer

A pointer that refers to a heap-dynamic variable that has already been deallocated, potentially leading to unpredictable behavior if accessed.

19
New cards

Lost heap-dynamic variable

A situation where a heap-dynamic variable is allocated but no longer accessible by any pointer in the program, resulting in memory that cannot be reclaimed.

20
New cards

Garbage

General term for unreachable heap-allocated memory that results from improper pointer reassignment.

21
New cards

Java, C++, C#

These languages introduce reference types to offer pointer-like flexibility with fewer risks.

22
New cards

Goto statement

Control structures like this can widen the range of memory accessible by a pointer, contributing to memory management complexity.

23
New cards

Heap-dynamic variables

A category of variables whose improper handling through pointers is a known source of programming problems.

24
New cards

Dangling pointer

A pointer-related error where both arrPtr1 and arrPtr2 become invalid after the memory pointed to by arrPtr2 is deallocated.

int* arrPtr1;
int* arrPtr2 = new int[10]; // allocate array on heap

arrPtr1 = arrPtr2;    // both point to the same memory

delete[] arrPtr2; //deallocate memory Now both arrPtr1 and arrPtr2 are dangling pointers

arrPtr1[0] = 42;  // Undefined behavior — memory may be reused!

25
New cards

Lost heap-dynamic variable

An error that occurs when ptr1 is reassigned to ptr2, making the originally allocated memory for ptr1 inaccessible.

int* ptr1 = new int(10);     // allocate memory for an integer
int* ptr2 = new int(20);     // allocate another integer

ptr1 = ptr2;             // memory originally pointed to by ptr1 is now lost

26
New cards

Reference Type

A C++ construct that acts like a constant pointer but refers directly to an object or value in memory without storing an address.

27
New cards

It must be initialized

What must happen when a C++ reference is declared?

int x = 10;
int& ref = x; // OK
int& ref2;    // Error

28
New cards

False

True or False

After a C++ reference is initialized, it can be reassigned to refer to another variable

29
New cards

A. Change the value of A to be 10

What does this code block do?

int a = 5, b = 10;
int& ref = a;
ref = b;      

A. Change the value of A to be 10

B. Rebind the reference to variable B

30
New cards

False

True or False

A C++ reference be assigned the value 0 or be null

31
New cards

False

True or False

A C++ reference requires dereferencing with the * operator to access the underlying value

32
New cards

False

True or False

"reference to reference" or "pointer to reference" constructs are allowed in C++

int x = 5;
int& &refRef = x;   
int& *ptrToRef = &x;

33
New cards

To implement pass-by-reference semantics

What is the primary use of C++ reference types in function parameters?

34
New cards

To support polymorphism via dynamic dispatch

In object-oriented C++, how are reference types used with virtual functions?

class Base {
public:
    virtual void speak() { std::cout << "Base\n"; }
};

class Derived : public Base {
public:
    void speak() override { std::cout << "Derived\n"; }
};

void callSpeak(Base& b) {
    b.speak(); 
}

35
New cards

Compatible Type

A type that is either legal for an operator or can be automatically converted to a legal type by compiler-generated code.

36
New cards

Coercion

The automatic, implicit conversion of a value from one type to another to make it compatible with an operator.

37
New cards

Type Checking

The process of ensuring that operands used with an operator are of compatible types.

38
New cards

The right-hand side must be compatible with the left-hand side

In an assignment statement, what must be true of the types of the right-hand and left-hand sides?

39
New cards

Mixed Mode Expression

An expression involving operands of different types, where coercion is used to make them compatible.

40
New cards

They can decrease the compiler’s ability to detect type errors

While useful, what is a potential downside of coercions during type checking?

41
New cards
  1. Unary +, Unary -, !

  2. *, /, % (modulus)

  3. +, -

  4. <, >, <=, >=

  5. ==, !=

  6. &&

  7. ||

List the operator precedence from highest to lowest in C-based languages, assuming standard rules.

42
New cards

Left to Right

What is the associativity of operators in C-based languages as per the given rules?

43
New cards
  • Each subprogram has a single entry point

  • The calling program is suspended during subprogram execution

  • Control returns to the caller when the subprogram finishes

  • Only one subprogram runs at a time

What are the four fundamental characteristics of subprograms according to most programming language models?

44
New cards

Static Local Variable

In C-based languages, what kind of local variable retains its value between function calls?

45
New cards

They are history sensitive, retaining their values between subprogram calls.

What is a key advantage of static local variables regarding persistence of values?

46
New cards

No allocation/deallocation is needed at each call; storage is statically bound.

Why do static local variables have lower time overhead compared to stack-dynamic variables?

47
New cards

Only once at the first call, not on every subsequent call.

When does initialization happen for a static local variable in C-based languages?

48
New cards

Because only one instance exists, shared across all recursive calls

Why are static local variables generally ineffective in recursive functions?

49
New cards

They remain allocated for the entire program duration, even when unused.

Compared to stack-dynamic variables, why might static locals be less space efficient?

50
New cards

Stack-dynamic

In most modern languages (C++, Java, Python, C#), what is the default storage class for local variables?

51
New cards

False

True or False

Stack-dynamic local variables retain their values between calls to the same subprogram

52
New cards

They often require indirect addressing via the activation record

Why might accessing stack-dynamic local variables be less efficient compared to static locals?

53
New cards

Allocation, deallocation, and initialization time at each call

What overhead is introduced by stack-dynamic local variables during subprogram execution?

54
New cards

Their storage is shared—different subprograms can reuse the same stack space

What memory efficiency advantage do stack-dynamic locals offer across multiple subprograms?

55
New cards

Each subprogram call gets its own unique instance of local variables

Why are stack-dynamic local variables essential for recursion?

56
New cards

Stack-dynamic

What type of local variable is automatically allocated on the runtime stack during a subprogram call and deallocated upon return?

57
New cards

Subprogram header

What is the first part of a subprogram definition called, containing its name, kind, and formal parameters?

58
New cards

Subprogram name, kind (e.g., procedure/function), and formal parameters

What three elements are included in a subprogram header?

59
New cards

Parameter profile (or signature)

What is the term for the number, order, and types of a subprogram’s parameters?

60
New cards

Subprogram protocol

What includes both the parameter profile and, for functions, the return type?

61
New cards

Prototype

What term is used in C and C++ to refer to a function declaration that provides the protocol but not the implementation?

62
New cards

Protocol

What part of a subprogram declaration provides the interface information but omits the subprogram body?

63
New cards

False
only if the subprogram is a function

True or False: A subprogram protocol always includes a return type.

64
New cards

Procedure

What is a subprogram that does not return a value?

65
New cards

Function

What is a subprogram that returns a value?

66
New cards

Side-effect-free computations (pure functions)

What mathematical model are functions ideally based on?

67
New cards

They can be used to define user-defined operators

Besides returning values, what is a notable feature of functions in some programming languages?

68
New cards

Subprograms

What term encompasses both functions and procedures as parameterized computations?

69
New cards

In mode

What parameter-passing mode copies the actual parameter into the subprogram at the beginning of execution?

70
New cards

Pass by value

What is the typical implementation of the "in mode" parameter-passing model?

71
New cards

Out mode

What parameter-passing mode copies the value out of the subprogram upon its completion?

72
New cards

Pass by result

What is the typical implementation of the "out mode" parameter-passing model?

73
New cards

Inout mode

What parameter-passing mode performs both input and output—copying in at the start and out at the end of subprogram execution?

74
New cards

Pass by reference

What is the typical implementation of the "inout mode" parameter-passing model?

75
New cards

Run-time stack

What common data structure is used to manage parameter passing during program execution?

76
New cards

Pass by reference

Which parameter-passing implementation involves giving the subprogram direct access to the caller’s variable?

77
New cards

Overloaded subprogram

What do we call a subprogram that shares its name with another subprogram in the same scope but differs in its protocol?

78
New cards

Its protocol (parameter profile and return type for functions)

What uniquely distinguishes each version of an overloaded subprogram?

79
New cards

Ada

In which language can overloaded functions be distinguished by their return type alone?

80
New cards

C++, Java, and C#

In which languages is the return type not used to disambiguate overloaded subprograms?

81
New cards

Ad hoc

What type of polymorphism do overloaded subprograms provide?

82
New cards

C++, Java, C#, and Ada

Which languages allow user-defined overloaded subprograms and include predefined overloaded functions and constructors?

83
New cards

Data Abstraction and Process Abstraction

What are the two fundamental abstraction facilities that programming languages can include?

84
New cards

Process abstraction

What form of abstraction is provided by subprograms like functions, subroutines, and methods?

85
New cards

Subprogram

What is a collection of statements that defines a parameterized computation and enables code reuse and modularity?

86
New cards

Data Abstraction

What abstraction facility was emphasized beginning in the 1980s to support modular, encapsulated data design?

87
New cards

Abstract Data Type

What is a user-defined data type that encapsulates a data structure and operations on it, while hiding internal representation

88
New cards

Packaging of data with operations and information hiding

What are the two main features of Abstract Data Types (ADTs)?

89
New cards

Class

What modern programming construct is used to implement ADTs as syntactic units?

90
New cards

True

True or False: All built-in data types in a language are considered abstract data types.

91
New cards

Heap

Where are all Java class instances allocated from?

92
New cards

Through Reference Variables

How are Java objects accessed?

93
New cards

new operator

What operator is typically used to create heap-dynamic objects in Java and C++?

94
New cards

Static, stack-dynamic, or heap-dynamic storage

In C++, where can class instances be allocated from?

95
New cards

delete

Which operator is used in C++ to destroy heap-dynamic objects?

96
New cards

Object slicing

What issue can occur in C++ when stack-dynamic objects of derived classes are assigned to base class variables?

97
New cards

pointers or reference variables

What allows uniform access to heap-dynamic C++ objects regardless of subtype?

98
New cards
99
New cards

To initialize objects when they are created

What is the purpose of a constructor in a class?

100
New cards

None

What return type is legally declared in a constructor’s definition?