Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[12 points] Consider the following program written in a language with the same syntax and semantics as Cexcept the used parameter passing method (check

[12 points] Consider the following program written in a language with the same syntax and semantics as Cexcept the used parameter passing method (check the question parts). void swap(int a, int b) { int tmp = a; a = b; b = tmp; } int main() { int arr[5] = {1,2,3,4,5}; int i = 4; swap(arr[0],arr[4]); Swap(i, arr[i]); } a) Show the values of i and arr after each swap call if the language uses pass-by-value method. After first swap call arr After second swap call i: arr: b) Show the values of i and arr after each swap call if the lanquage uses pass-by-reference method. After first swap call arr After second swap call i: arr: c) Show the values of i and arr after each swap call if the language uses pass-by-name method. After first swap call arr After second swap call i: arr: d) Show the values of i and arr after each swap call if the language uses pass-by-value-result method. Assume that we transfer the parameters in the same order of the arguments in the call and the address of an argument is computed during the subprogram call, not the return. After first swap call arr After second swap i: arr:

Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

aPassedbyvalue Passedbyvalue retains the actual values of the arguments pas... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discrete and Combinatorial Mathematics An Applied Introduction

Authors: Ralph P. Grimaldi

5th edition

201726343, 978-0201726343

More Books

Students also viewed these Programming questions

Question

Recognise income tax and capital gains tax

Answered: 1 week ago

Question

Verify that [p (q r)] [(p q) (p r)] is a tautology.

Answered: 1 week ago