Professional Documents
Culture Documents
Some Questions of First 2013-14
Some Questions of First 2013-14
Some Questions of First 2013-14
Q1. The code fragment given below follow all the features and syntax of C programming language but support dynamic
scoping. Using the code argue that the use of dynamic scoping need dynamic typing instead of static typing.
(Answer to the point. Unnecessary explanation will not fetch marks). 2M
Q2. Given the C-based program fragment, Classify the variables in the program according to their lifetime. 2M
a. In C global variables need not be declared in the beginning of the program i.e., global variables can be declared
external to any function and are visible to all functions which follow its declaration. What property of programming
languages it satisfies and what property of programming language it violate.
b. If True and False are of Boolean type, True < False is legal statement in C but illegal in Java. Make two wise
comments on implementation of Boolean type in C and Java w.r.t properties of programming language.
Q4. Consider the code fragment written in some program language where parameters are passed by reference. The
removeDuplicates( ) function is intended to release the memory allocated for the duplicate variables. Make two
wise negative comment on the program. 2M
Q1. Consider the program fragment which support dynamic scoping. Assume that execution of the
program will always start from driver( ) function. (Expected time 15 min. 2+2+2+2+1+3=12M)
void fun3( ) void fun2( ) void fun1( ) Global declare int min=0,a=9,c=8;
{ { { driver( )
min=(min<c)?min:c; declare int b=15; declare int b; {
} declare int c=3; a=6; declare int a=15,b=13,c=22;
min= (a<b)?a :b; b=1; fun1( );
fun3( ); c=5; Write( min );
} fun2( ); }
}
a. Show the run time stack with all activation record instances when fun3 is executing and dynamic
scoping is implemented using i. Deep access ii. Shallow access.
(Content of ARI should be arranged as follows: Return address, Dynamic Link, Static Link,
Parameter list, Local variables, Return value).
b. What is the output when dynamic scoping is used ? Justify.
c. What is the output when static scoping is used ? Justify.
d. When is shallow access implementation of dynamic scoping is preferred over deep access
implementation ?
e. If the above functions are nested as given below. Give the reference pair (chain offset, local
offset) for each variables at Position 1, Position 2 and Position 3 in the functions. (assume depth
of driver function is 1)
void fun3( )
{
min=(min<c)? min : c;--------> Position 3
}//endfun3
fun3( );
}//end fun2
fun2( );
}//end fun1
fun1( );
Write( min );
}
Q2. Consider the program fragment of programming language which support static scoping.
Assume that execution of the program will always start from driver function.
(Expected time 10 min. 2+ 4+2= 8M )
Global declare int n =6;
driver( )
{
declare int a[n], i, j;
for( i=n-1; i>=0; i--)
a[i]=i+1;
fun1( a[n-3], a[n-4], a[n-5]);
i=n;
fun2(i, a[i-2], a[i-3], a[i-4]);
Write( i );
for( i=n; i>=0; i--)
Write( a[i] );
}
void fun1( int p, int q, int r) void fun2(int x, int p, int q, int r)
{ {
int min; while(x>4)
n=n+2; {
min= (p<q) ? p : q; x=x-1;
min= (min<r) ? min : r; p= q+r;
Write( min ); q= q++;
} r=r++;
}
}