Lecture 12 Flashcards

1
Q

What is Pass-by-Value in parameter passing?

A

Pass-by-Value copies the actual parameter’s value to the formal parameter. Changes to the formal parameter do not affect the actual parameter. It is used in languages like C, C++, and Java (for primitive types).

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

What is pass-by-Result in parameter passing?

A

In Pass-by-Result, the formal parameter acts as a local variable whose value is copied back to the actual parameter when the subprogram exits. Changes to the formal parameter are reflected in the actual parameter after execution.

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

What is Pass-by-Value-Result in parameter passing?

A

Pass-by-Value-Result combines pass-by-value and pass-by-result. The actual parameter’s value is copied to the formal parameter at the beginning and back to the actual parameter at the end of the subprogram.

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

What is Pass-by-Reference in parameter passing?

A

Pass-by-Reference makes the formal parameter an alias for the actual parameter, allowing changes to the formal parameter to directly affect the actual parameter. Used in C++ (pointers), Java (objects), and C#.

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

What is Pass-by-Name in parameter passing?

A

Pass-by-Name directly substitutes the actual parameter into the subprogram, using a late binding mechanism where the expression is evaluated each time it is used. Implemented using thunks.

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

How are parameters and return addresses managed in stack-based implementation?

A

Parameters and return addresses are stored on the runtime stack using activation records, which manage information for each active subprogram, including local variables, parameters, return address, and control information.

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

How are parameters passed in C/C++?

A

C/C++ use pass-by-value for basic types and pass-by-reference using pointers.

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

What parameter passing modes does Ada support?

A

Ada supports in, out, and inout parameter passing modes.

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

How are parameters passed in Fortran?

A

Fortran primarily uses pass-by-reference for parameter passing.

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

What is aliasing and what problems can it cause?

A

Aliasing occurs when multiple variables reference the same memory location, leading to unexpected side effects and bugs, especially in pass-by-reference and pass-by-name parameter passing.

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

What are address conflicts in parameter passing?

A

Address conflicts occur when two parameters reference the same memory location, potentially leading to unintended interactions between parameters.

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

What are the efficiency concerns with pass-by-value?

A

Copying large data structures in pass-by-value can be inefficient, making it less suitable for large or complex data.

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

What are the best practices for choosing parameter passing mechanisms?

A

Use pass-by-value for small, immutable data, and pass-by-reference for large data structures and when modifications are needed. Avoid pass-by-name unless necessary for specific scenarios.

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

What are the advantages of pass-by-reference?

A

Pass-by-reference is efficient because it avoids copying large data structures, but it can lead to aliasing and side effects.

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