0% found this document useful (0 votes)
4 views5 pages

RGM PL5

Uploaded by

manan grover
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

RGM PL5

Uploaded by

manan grover
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Parameter and Parameter transmission schemes

Parameters are variables used to pass data to functions, procedures, ar subroutines,


enabling modular programming and code reuse
The method by which parameters are passed from the calling function is known as
Scheme. to called function the 'Parameter transmission.

Mention the importance of these schemes:

They affect performance, memory usage, and wheather changes in the called function
affect the original data
Types of Parameter Transmission Schemes

- Pass by value:-

Description:- A copy of the variable is passed to the function. The original variable
remains. Unaffected.

Advantages safer as the original data is protected


Disadvantages: - Inefficient for large data stevectures like arrays or objects

Example

void increment (int x) { x=x+1;

int main() 2
int y = 5;

increment (Y):
Print f (“%d”, Y); //

Output: 5

Return 0;

2. Pass by Reference=

Description:- A reference (memory address) to the variable is passed changes inside


the function affect the original variable
Advantages: Efficient for large data structures.
Disadvantages= Risky as the quiginal variable can be inadvertently modified.

Example-

C++

Void increment (int &x) { x=x+1;

Int main() {

Int y = 5;

Increment (Y);

Cout <<Y; // output: 6 return 0;


}

Pass by Value- Result (Copy-IN/ Copy-Out)

Description: A copy of the variable is passed and after the function executes, the result
is copied back to the original variable
Advantage: Combines the benefits of value and reference passing

Disadvantages= Can be inefficient for large data structure.

Example (Pseudocode)

Pseudocode

Procedure updata (X)


X = x+5,

Y = 10;

Call update (Y);

// Y is updated to 15 after the function ends.

pass by Result :-

Description:- Only the final result of the parameter is passed back to the caller. No
initial value is sent to the function.
Advantages Useful for output only variables Disadvantages Undefined behaviour if the
variable is used before the function ends.
Pseudocode

Procedure assign-result(x)

X = 20;

Assign-result (y);

// y gets the value 20 after

The procedure Call

Pass by Name

Description= The actual code or expression of the Parameter is subsituted in the


function.
Re-evaluation happens every time the parameter is used
Advantages= Allows flexible evaluation.

Disadvantages: Difficult to debug and may

Lead to inefficiencies. Example. CALGOL Like Pseudocode):

Pseudocode

Procedure examp(x)

Print (x+x);

Example (a+1); // x is evaluat ed as (a+1) each time, so output is 12.

Comparison of schemes & Scheme Pass by value Original variable Modified – No


Efficiency low for large data Use case Protect original data.

Pass by Reference –

YesPass by value result

Sometimes
Moderate

Combines safety and efficiency.

Pass by Result

Yes (at the end)

Moderate

Output only parameters.

Pass by Name

Depends on usage

Lazy evaluation for macros

Conclusion:-

The choice of Parameter. Dep ends Safety, transmission scheme on factors like
performance, and ease of debugging

Modern programming languages often use pass by value with or pass by reference,
variations (eg. Python’s reference

High Efficient for large date structures

Pass by value result

Sometimes

Moderate

Combines safety and efficiency.

Pass by Result

Yes (at the end)

Moderate
Output only parameters.
Pass by Name

Depends on usage

Lazy evaluation for macros

Conclusion:-

The choice of Parameter. Dep ends Safety, transmission scheme on factors like
performance, and ease of debugging

Modern programming languages often use pass by value with or pass by reference,
variations (eg. Python’s reference model

You might also like