Quiz 12 Flashcards

(10 cards)

1
Q

What is a dangling reference in programming?
A variable pointing to a memory location that has been deallocated or is no longer valid
A variable that points to a null memory address
A reference that points to a null memory address
A pointer that always points to a constant memory location

A

A variable pointing to a memory location that has been deallocated or is no longer valid

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

Which of the following functions in C is used for dynamic memory location?
printf
malloc
static
sizeof

A

malloc

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

What is a potential risk of aliasing?
Increased memory usage
Performance degradation due to redundant copies
Errors caused by uninitialized variables
Unintended side effects when modifying one alias

A

Unintended side effects when modifying one alias

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

How is a constant different from a variable?
A constant can be reassigned during execution
A constant requires dynamic memory allocation
A constant does not have a type attribute
A constant does not have a location attribute

A

A constant does not have a location attribute

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

Which of the following types of variables typically has the longest lifetime?
Variables declared inside loops
Global variables
Function parameters
Local variables in a function

A

Global variables

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

Which type of assignment is typically used in Python for mutable objects like lists and dictionaries?
Assignment by pointer
Assignment by value
Assignment by cloning
Assignment by sharing

A

Assignment by sharing

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

What is the main purpose of garbage collection in memory management?
To deallocate memory no longer in use, preventing memory leaks
To manage static variables at compile time
To allocate memory for program variables
To optimize cache usage during program execution

A

To deallocate memory no longer in use, preventing memory leaks

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

What is the “environment” in programming?
The physical memory where the program runs
The hardware on which the program executes
A set of bindings that associates variables with their values or funcitons
The collection of syntax rules in a programming language

A

A set of bindings that associates variables with their values or functions

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

What does a “lifetime” of a variable refer to?
The size of the variables in memory
The duration of its allocation in the environment
The number of times a variable is referenced in a program
The duration of the program’s execution

A

The duration of its allocation in the environment

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

Which programming language primarily emphasizes value semantics?
JavaScript for objects and arrays
C++ when using primitive types
Python for all data types
Java for all objects

A

C++ when using primitive types

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