Which one of the following expressions, when placed in the blank above, will NOT result in a
type checking error?
Answer : Option DExplaination / Solution:
Here function f takes two arguments one is int and the other is short and its return type is void.
So, in main function ‘P’ is a pointer to short and when we call f (i,*p) there won’t be any type
checking error.
Match the algorithms to the design paradigms they are based on.
Answer : Option CExplaination / Solution:
Kruskal’s algorithm follows greedy approach in order to find MST of a connected graph.
Quick sort follows divide and conquer strategy. Floyd Warshal algorithm is used to find the
shortest path between every pair of vertices and it follows dynamic programming strategy.
Q4.Consider the C functions foo and bar given below:
int foo (int val ) {
int x = 0;
while (val > 0) {
x = x + foo ( val --);
}
return val ;
}
int bar (int val ) {
int x = 0;
while (val > 0) {
x = x + bar (val – 1) ;
}
return val ;
}
Invocations of foo (3) and bar (3) will result in:
Answer : Option BExplaination / Solution:
Foo (3) calls foo (3) which in turn calls foo(3). This goes on infinite number of times which
causes memory overflow and causes abnormal termination.
Bar(3) → bar (2) →bar (1) →bar (0) (return 0) from here onwards bar (1) will call bar (0)
and bar (0) will return 0 to bar (1) & this goes on forever without causing memory overflow.
Answer : Option AExplaination / Solution:
In this the fun1() is calling fun2() after printing value and after returning from fun2(),it prints
the same value. In the fun2() also the same thing happens So by looking options we can judge
the correct sequence of output.