284 views
0 votes
0 votes
Consider the following code.
int a = 1;
int b = 1;
Function foo() {
print(a);
}
Function bar(int x, int y){
int a = 0;
foo() ;
x = 0 ;
b = b-y;
r = Y+1;
}
Function foobar() {
int r = 1 ;
bar(r,b);
print(b);
print(r);
}
Suppose that foobar() is called from the outermost scope. Which of the following statements is/are true?
I. If dynamic scoping is used, then the first digit printed is 1, regardless of how parameters are passed (by value, reference, or value-result).
II. If lexical scoping and pass-by-value-result are used, then the second digit printed is 1.
III. If lexical scoping and pass-by-value are used, then the third digit printed is 1.
A. III only
B. I and II only
C. II and III only
D. I, II, and III

Answer is given a A..In III lexical scope is mentioned..So how will the function bar( int x,int y) access the variable 'r'?..it is local to fooBar()..i think this will throw compilation error..can anyone verify.

Please log in or register to answer this question.

Related questions

3 votes
3 votes
2 answers
2
sunil sarode asked Nov 4, 2017
2,169 views
Choose the False statements:(a) The scope of a macro definition need not be the entire program(b) The scope of a macro definition extends from the point of definition to ...