1/108
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Descriptors
The collection of attributes of a variable
type checking, allocation, and deallocation
What are descriptors used for?
Descriptor of Static Attributes
Type of descriptor required only at compile-time; typically built as part of the symbol table.
Descriptor for Static Attributes
Descriptor type used for compile-time features like static string length and static attributes of arrays
Descriptor of dynamic attributes
Type of descriptor that must be used and maintained by the run-time system.
Descriptor dynamic attributes
Descriptor used at run-time for values like limited dynamic strings.
Row major order
A method of storing multi-dimensional array elements in memory by rows, where elements of each row are stored contiguously.
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.
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
Column Major Order
Storage order for arrays typically used in Fortran.
Row Major Order
Storage order for arrays typically used in most programming languages (e.g., C, Java, Python).
Access function
A mechanism used in array implementation that maps subscript expressions to a memory address.
Access function for memory address of an element in a single-dimensional array
address(list[k]) = address(list) + (k * element_size)
0
In languages like C, C++, and Java, what is the typical lower bound for array indexing?
Simplified version of the access function for 2D arrays assuming 0-based indexing
Location(a[i,j]) = base_address + ((i * n) + j) * element_size
Access function
When no index range checking is performed and all array attributes are static, what is the primary mechanism used to locate elements?
Dangling Pointers and Lost Heap Dynamic Variables
What are the two common problems of pointers?
Dangling pointer
A pointer that refers to a heap-dynamic variable that has already been deallocated, potentially leading to unpredictable behavior if accessed.
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.
Garbage
General term for unreachable heap-allocated memory that results from improper pointer reassignment.
Java, C++, C#
These languages introduce reference types to offer pointer-like flexibility with fewer risks.
Goto statement
Control structures like this can widen the range of memory accessible by a pointer, contributing to memory management complexity.
Heap-dynamic variables
A category of variables whose improper handling through pointers is a known source of programming problems.
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!
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
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.
It must be initialized
What must happen when a C++ reference is declared?
int x = 10;
int& ref = x; // OK
int& ref2; // Error
False
True or False
After a C++ reference is initialized, it can be reassigned to refer to another variable
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
False
True or False
A C++ reference be assigned the value 0 or be null
False
True or False
A C++ reference requires dereferencing with the *
operator to access the underlying value
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;
To implement pass-by-reference semantics
What is the primary use of C++ reference types in function parameters?
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();
}
Compatible Type
A type that is either legal for an operator or can be automatically converted to a legal type by compiler-generated code.
Coercion
The automatic, implicit conversion of a value from one type to another to make it compatible with an operator.
Type Checking
The process of ensuring that operands used with an operator are of compatible types.
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?
Mixed Mode Expression
An expression involving operands of different types, where coercion is used to make them compatible.
They can decrease the compiler’s ability to detect type errors
While useful, what is a potential downside of coercions during type checking?
Unary +
, Unary -
, !
*
, /
, %
(modulus)
+
, -
<
, >
, <=
, >=
==
, !=
&&
||
List the operator precedence from highest to lowest in C-based languages, assuming standard rules.
Left to Right
What is the associativity of operators in C-based languages as per the given rules?
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?
Static Local Variable
In C-based languages, what kind of local variable retains its value between function calls?
They are history sensitive, retaining their values between subprogram calls.
What is a key advantage of static local variables regarding persistence of values?
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?
Only once at the first call, not on every subsequent call.
When does initialization happen for a static local variable in C-based languages?
Because only one instance exists, shared across all recursive calls
Why are static local variables generally ineffective in recursive functions?
They remain allocated for the entire program duration, even when unused.
Compared to stack-dynamic variables, why might static locals be less space efficient?
Stack-dynamic
In most modern languages (C++, Java, Python, C#), what is the default storage class for local variables?
False
True or False
Stack-dynamic local variables retain their values between calls to the same subprogram
They often require indirect addressing via the activation record
Why might accessing stack-dynamic local variables be less efficient compared to static locals?
Allocation, deallocation, and initialization time at each call
What overhead is introduced by stack-dynamic local variables during subprogram execution?
Their storage is shared—different subprograms can reuse the same stack space
What memory efficiency advantage do stack-dynamic locals offer across multiple subprograms?
Each subprogram call gets its own unique instance of local variables
Why are stack-dynamic local variables essential for recursion?
Stack-dynamic
What type of local variable is automatically allocated on the runtime stack during a subprogram call and deallocated upon return?
Subprogram header
What is the first part of a subprogram definition called, containing its name, kind, and formal parameters?
Subprogram name, kind (e.g., procedure/function), and formal parameters
What three elements are included in a subprogram header?
Parameter profile (or signature)
What is the term for the number, order, and types of a subprogram’s parameters?
Subprogram protocol
What includes both the parameter profile and, for functions, the return type?
Prototype
What term is used in C and C++ to refer to a function declaration that provides the protocol but not the implementation?
Protocol
What part of a subprogram declaration provides the interface information but omits the subprogram body?
False
only if the subprogram is a function
True or False: A subprogram protocol always includes a return type.
Procedure
What is a subprogram that does not return a value?
Function
What is a subprogram that returns a value?
Side-effect-free computations (pure functions)
What mathematical model are functions ideally based on?
They can be used to define user-defined operators
Besides returning values, what is a notable feature of functions in some programming languages?
Subprograms
What term encompasses both functions and procedures as parameterized computations?
In mode
What parameter-passing mode copies the actual parameter into the subprogram at the beginning of execution?
Pass by value
What is the typical implementation of the "in mode" parameter-passing model?
Out mode
What parameter-passing mode copies the value out of the subprogram upon its completion?
Pass by result
What is the typical implementation of the "out mode" parameter-passing model?
Inout mode
What parameter-passing mode performs both input and output—copying in at the start and out at the end of subprogram execution?
Pass by reference
What is the typical implementation of the "inout mode" parameter-passing model?
Run-time stack
What common data structure is used to manage parameter passing during program execution?
Pass by reference
Which parameter-passing implementation involves giving the subprogram direct access to the caller’s variable?
Overloaded subprogram
What do we call a subprogram that shares its name with another subprogram in the same scope but differs in its protocol?
Its protocol (parameter profile and return type for functions)
What uniquely distinguishes each version of an overloaded subprogram?
Ada
In which language can overloaded functions be distinguished by their return type alone?
C++, Java, and C#
In which languages is the return type not used to disambiguate overloaded subprograms?
Ad hoc
What type of polymorphism do overloaded subprograms provide?
C++, Java, C#, and Ada
Which languages allow user-defined overloaded subprograms and include predefined overloaded functions and constructors?
Data Abstraction and Process Abstraction
What are the two fundamental abstraction facilities that programming languages can include?
Process abstraction
What form of abstraction is provided by subprograms like functions, subroutines, and methods?
Subprogram
What is a collection of statements that defines a parameterized computation and enables code reuse and modularity?
Data Abstraction
What abstraction facility was emphasized beginning in the 1980s to support modular, encapsulated data design?
Abstract Data Type
What is a user-defined data type that encapsulates a data structure and operations on it, while hiding internal representation
Packaging of data with operations and information hiding
What are the two main features of Abstract Data Types (ADTs)?
Class
What modern programming construct is used to implement ADTs as syntactic units?
True
True or False: All built-in data types in a language are considered abstract data types.
Heap
Where are all Java class instances allocated from?
Through Reference Variables
How are Java objects accessed?
new
operator
What operator is typically used to create heap-dynamic objects in Java and C++?
Static, stack-dynamic, or heap-dynamic storage
In C++, where can class instances be allocated from?
delete
Which operator is used in C++ to destroy heap-dynamic objects?
Object slicing
What issue can occur in C++ when stack-dynamic objects of derived classes are assigned to base class variables?
pointers or reference variables
What allows uniform access to heap-dynamic C++ objects regardless of subtype?
To initialize objects when they are created
What is the purpose of a constructor in a class?
None
What return type is legally declared in a constructor’s definition?