3,292 views
7 votes
7 votes

Consider the block of code given below:

Program PARAM(input,output);
var m,n:integer;

procedure P(var x,y:integer);
var m:integer;
begin
m:=1;
x:=y+1;
end;

procedure Q(x:integer; var y:integer);
begin
x:=y+1;
end;


begin
m:=0; P(m,m);write(m);
n=0; Q(n*1,n);write(n)
end;


30. The value of m, output by the program PARAM is
a)1, because m is a local variable in P
b)0, because m is the actual parameter that corresponds to the formal parameter in P
c) 0, because both x and y are just reference to m and y has the value 0
d)1, because both x and y are just references to m which gets modified in procedure p


31. The value of n, output by the program PARAM is
a)0, because n is the actual parameter corresponding to x in procedure Q
b)0, because n is the actual parameter to y in procedure Q
c)1, because n is the actual parameter corresponding to x in procedure Q
d)1, because n is the actual parameter corresponding to y in procedure Q
e)None of the above



32. What is the scope of m declared in the main program?
a)PARAM,P,Q

b)PARAM,P

c)PARAM,Q

d)P,Q

4 Answers

5 votes
5 votes
30.  Option b, 0, because goobal m is not modified, m is just passed to formal arguments of P.

31. Option e, 0, because n is just passed to formal parameters of Q and no modification in global n.

32. Option a, since m is defined global it is visible inside all the procedures.
5 votes
5 votes
30-option (D) is correct ,in Pascal ,integer pointer variable is declared as "var p:integer" and integer variable is declared as "v:integer"

Procedure P(var x,y:integer):x and y are pointer variables,so P uses call by reference for x and y

=>m=1

31-option (B) is correct,

Procedure Q(x:integer,var y:integer):x is integer variable and y is  pointer ,so Q uses call by value for x and call by reference for y.

=>n=0

32-option (C) is correct

m is declared in the main program and its scope is limited to PARAM and Q.m can not be accessible in P,because P has local variable with same name 'm'.
0 votes
0 votes
somebody please say the correct answer with appropriate  reason  of Queen no 30
0 votes
0 votes
32: The answer is a.

As you can see m is declared in main program is global variable .

So it's scope is Param , P,Q

31. I think answer is e

Because would be b but it states that n is actual parameter to y in procedure Q.

30. b is right answer , here it call by value .

Related questions

0 votes
0 votes
1 answer
3
Arun Rout asked Jan 7, 2019
728 views
#include<stdio.h>int fun(int arr[]){ arr=arr+1; printf("%d",arr[0]);}int main(void){ int arr ={10,20}; fun(arr); printf("%d",arr[0]); return 0;}A.COMPIL...
0 votes
0 votes
1 answer
4
Balaji Jegan asked Nov 15, 2018
1,326 views
Predict the Output for both the snippets for the following:1. Call by Value2. Call by Reference3. Call by Need4. Call by Name5. Call by value Result/Call by value Return(...