retagged by
863 views

4 Answers

2 votes
2 votes

36) 10

37) -90

38) 20

39) 0

0 votes
0 votes

36. call by value and static scope

In main() a is assigned as 10. Now, f(10) function is called,So, f(b) copied the value of value of a in b, then b=10. Now, multiplication of b*a=10*2=20(where a takes the value of global variable a). Finally a becomes 2-20=-18. and it will update the global variable a=-18

As it is call by value, when it prints it will take value of local to main()=10

37.call by value and dynamic scope

In main() a is assigned as 10. Now, f(10) function is called,So, f(b) copied the value of value of a in b, then b=10. Now, multiplication of b*a=10*10=100(where a takes the value from where it is called , i.e. main()). Finally a becomes 10-100=-90. and it will update the global variable a=-90

But as it is dynamic scope, value of a will be updated value=-90

38.call by reference and static scope

a assigned the value of 10. f(10) is passed to b, means b also points to 10. Now, b updates to b=10*2=20. value of a updates to -18.

And finally print -18.

39.call by reference and dynamic scope

In main() a is assigned as 10. Now, f(10) function is called,So, f(b) pointed to same memory as a, the value of value of a in b, then b=10. Now, multiplication of b*a=10*10=100(where a takes the value of global variable a). global a updates to 100.

Now, a updates to a-b=0

So, 0 will be prined.

edited by
0 votes
0 votes

a) call by value and lexical scope:-  10

 this is because whatever manipulation are done in variable a inside function f() will not be reflected in main() due to its limited scope i.e. lexical scope. so the value of a will remain 10


b) call by value and dynamic scope: -90

   when variable a will be passed the value of variable b will become 10. Note that a and b will have differerent memory location.now get inside the function f()

    b= b*a // b= 10*10 (since dynamic scope is used so value of variable a will be taken as 10 only)

   a= a-b // a= 10-100 = -90


d) call by refernce and dynamic scoping:-  0

when variable a will be passed the value of variable b will become 10. Note that a and b will have same memory location because call by reference is used..now get inside the function f()

    b= b*a // b= 10*10 (since dynamic scope is used so value of variable a will be taken as 10 only)

thus b becomes 100. same changes will be reflected in a due to call by reference property. so value of a also will become 100.

   a= a-b // a= 100-100 = 0

c) call by reference and lexical scoping :- The answer is 20 but i dont know the procedure. kindly explain @kevalKubavat

    

0 votes
0 votes

36. call by value and static scope

In main() a is assigned as 10. Now, f(10) function is called,So, f(b) copied the value of value of a in b, then b=10. Now, multiplication of b*a=10*2=20(where a takes the value of global variable a). Finally a becomes 2-20=-18. and it will update the global variable a=-18

As it is call by value, when it prints it will take value of local to main()=10

37.call by value and dynamic scope

In main() a is assigned as 10. Now, f(10) function is called,So, f(b) copied the value of value of a in b, then b=10. Now, multiplication of b*a=10*10=100(where a takes the value from where it is called , i.e. main()). Finally a becomes 10-100=-90. and it will update the global variable a=-90

But as it is dynamic scope, value of a will be updated value=-90

38.call by reference and static scope

a assigned the value of 10. f(10) is passed to b, means b also points to 10. Now, b updates to b=10*2=20. value of a updates to -18.global

And finally print 20

39.call by reference and dynamic scope

In main() a is assigned as 10. Now, f(10) function is called,So, f(b) pointed to same memory as a, the value of value of a in b, then b=10. Now, multiplication of b*a=10*10=100(where a takes the value of global variable a). global a updates to 100.

Now, a updates to a-b=0

So, 0 will be prined.

Related questions

1 votes
1 votes
1 answer
1
Mukesh Yadav asked Oct 25, 2017
293 views
main() { int xyz; st1; st2(); f(); g(); h(); st3; ) how many stack entry required??ans is 2 why??
0 votes
0 votes
1 answer
2
shashank023 asked Jun 17, 2017
979 views
How storage mapping is done by compilers ?Even though actual loading of program in memory is done by loader.PS: This is the exact question as given in book, but i think i...
1 votes
1 votes
2 answers
3
1 votes
1 votes
0 answers
4
mobashshir asked Aug 29, 2018
423 views
Plz some one give me os madeasy answers key of chapter virtual memory and disk schedulingPlz it is request