Functions
Q1.
Consider the following ANSI C program #include < stdio.h > int foo(int x, int y, int q) { if ((x < = 0) && (y < = 0)) return q; if (x < = 0) return foo(x, y-q, q); if (y < = 0) return foo(x-q, y, q); return foo(x, y-q, q) + foo(x-q, y, q); } int main( ) { int r = foo(15, 15, 10); printf("%d", r); return 0; } The output of the program upon execution is ____Q2.
Consider the following program: int main() { f1(); f2(2); f3(); return(0); } int f1() { return(1); } int f2(int X) { f3(); if (X==1) return f1(); else return (X*f2(X-1)); } int f3() { return(5); } Which one of the following options represents the activation tree corresponding to the main function?Q3.
The integer value printed by the ANSI-C program given below is ______.#include < stdio.h > int funcp(){ static int x = 1; x++; return x; } int main(){ int x,y; x = funcp(); y = funcp()+x; printf("%d\n", (x+y)); return 0; }Q4.
Consider the following ANSI C function: int SimpleFunction(int Y[], int n, int x) { int total = Y[0], loopIndex; for (loopIndex=1; loopIndex<=n-1; loopIndex++) total=x*total +Y[loopIndex]; return total; } Let Z be an array of 10 elements with Z[i]=1, for all i such that 0\leq i \leq 9. The value returned by SimpleFunction(Z,10,2) is __________Q5.
Consider the following C program. void f(int,short); void main() { int i=100; short s=12; short *p=&s __________ ;//calltof() } Which one of the following expressions, when placed in the blank above, will NOT result in a typec hecking error?Q6.
Consider the following C program: #include int jumble(int x, int y) { x = 2 * x + y; return x; } int main() { int x = 2, y = 5; y = jumble(y, x); x = jumble(y, x); printf("%dn", x); return 0; } The value printed by program is __________ .Q7.
Consider the following C program: void convert(int n) { if (n<0) printf("%d",n); else { convert(n/2); printf("%d",n%2); } } Which one of the following will happen when the function convert is called with any positive integer n as argument?Q8.
Consider the following C program: #include < stdio.h > int counter = 0; int calc (int a, int b) { int c; counter++; if (b==3) return (a*a*a); else { c = calc(a, b/3); return (c*c*c); } } int main (){ calc(4, 81); printf ("%d", counter); } The output of this program is _____.Q9.
The value printed by the following program is . void f(int*p, int m){ m =m+5; *p =*p+m; return; } void main(){ int i=5, j=10; f(&i, j); printf("%d", i+j); }Q10.
Consider the following C code segment int f(int x) { if(x<1) return 1; else return (f(x-1) + g(x)); } int g(int x) { if(x<2) return 2; else return (f(x-1) + g(x/2)); }Of the following, which best describes the growth of f(x) as a function of x ?