Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Language Problem set 5 and 7 1)Pass by value 2)Pass by reference 3)P

ID: 3703818 • Letter: P

Question

Programming Language
Problem set 5 and 7 1)Pass by value 2)Pass by reference 3)Pass by value-result Draw a table for your results You should have 9 sets of results for #5(do them in the above order) S. Consider the following program written in C syntax: void swap (int a,int b int temp tempai b tep void main) int value 2, list [5(1, 3, 5, 7, 9]h swap (value, list o]) swap (list to, list [1]) swap (value, list [value]) For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap? a. Passed by value b. Passed by reference c. Passed by value-result 6. Present one argument against providing both static and dynamic local variables in subprograms 7. Consider the following program written in C syntax void fun (int first, int second) first first Programming Exercises 439 second +second; void mainO int list [2, 3) fun (1ist [o, 1ist [11) For each of the following parameter-passing methods, what are the val- ues of the 1ist array after execution? a. Passed by value b. Passed by reference c. Passed by value-result 8. Argue against the C design of providing only function subprograms 9. From a textbook on Fortran, learn the syntax and semantics of statement functions. Justify their existence in Fortran. Study the methods of user-defined operator overloading in C++ and Ada, and write a report comparing the two using our criteria for evaluating languages 10.

Explanation / Answer

5) a) Passed by value:

The concept of pssed by value, in C programming states a copy of variables is created, that contains the same values at the time of the call of the function,

For function swap(value, list[0])

after return the variables will be, value=2, and list[0]=1

For, function swap(list[0], list[1])

after return the variables contains, list[0]=1, list[1]=3

For, function swap(value, list[value])

after return valuee be like: value=2, and list[value]=5

the values of the varibale now are,

value=2, list[5]={1,3,5,7,9}

5) b) passed by reference: The concept of passed by reference, states that a same alias is created for the representing variable, that is

for function swap(value, list[0])

after return, value=1, and list[0]=2

for, function swap(list[0], list[1])

after return, list[0]=3, list[1]=2

For, function swap(value, list[value])

after return, value=1, and list[1]=2

the variables now are,

value=1, list[5]={3,2,5,7,9}

5) c)Passed by value-result: The concept of passed by value result shows that, when the parameter are passing, the value is returned to the actual parameter if the parameter is a mutable entity e.g, array or variable else the value will not pass, that is

for function swap(value, list[0])

after return, value=1, and list[0]=2

for, function swap(list[0], list[1])

after return, list[0]=3, list[1]=2

For, function swap(value, list[value])

after return, value=1, and list[1]=2

the variables now are,

value=1, list[5]={3,2,5,7,9}

6) In subprograms, the local vairables can act as either static or dynamic

static local vaibales in subprogram: static local vairables means that the allocation and deallocation in the memory for the location is done at compile-time, this allows proper type-checking for the variable but it is not possibe to allow recursion.

dynamic local varibales in subprogram: dynamic local variables can also be allowed in the subprograms, dynamic variables are assigned the memory locations at run-time, that is both allocation and deallocation of such variables is supposed to be on run-time, vis-a-vis they support the functionality of recursion, implemented at run-time by the help of stack positioning.

7) a) Passed by value

after returning, list[2]= {1,3}

7) b) Passed by reference:

after return, list[2]={2,6}

7) c) Passed by value-result

after return, list[2]={2,6}

Please give a thumbs up, if you are satisfied with the answer or leave a comment in the comment box, I will try to elaborate further, on the subject matter.

value list[0] a b temp 2 1 2 1 2 2 1 1 2 2