However the values in these local versions are copied back to the original

However the values in these local versions are copied

This preview shows page 2 - 4 out of 4 pages.

value-result works by creating local versions of the parameters passed in. However, thevalues in these local versions are copied back to the original arguments after the end ofthe procedure.In case of exceptions, results may differ. Let us see below example in an arbitrarylanguageint addTwo(a, b)
Image of page 2
{a = a + b;b = a + b;return b;}If call-by-value-result is used then calling addTwo(x, x) will return 3x (see below for explanation).a = a + b; will result in a = x + xb = a + b; will result in b = 2x + x If call-by-reference is used then addTwo(x, x) will return 4x (see below for explanation).a = a + b; will result in a = x + xb = a + b; will result in b = 2x + 2x 25. Consider the following programProgram P2 var n: int: procedure W(var x: int) beginx=x+1; print x; endprocedure D begin var n: int; n=3; W(n); endbegin //beginP2 n=10; D; EndIf the language has dynamic scoping and parameters are passed by reference, what will beprintedbytheprogram?
Image of page 3
Answer(d) Program will print 4. 26. Discuss various concepts of object oriented programming.27. Explain imperative programming.
Image of page 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture