Machine-translated by Google. Questions are authored in English.
Top

Functions Questions and Answers

11.

Recursion must have a __________ to stop infinite calls.

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: B

Recursion must have a base case to stop infinite calls.

A recursive function calls itself on a smaller version of the problem. The base case is the condition under which it returns a result directly without calling itself, for example factorial(0) = 1. Without it, the calls would never end and the program would run out of stack space (a stack overflow).

A loop is the alternative to recursion, not part of it. A return type and a global variable do nothing to stop the chain of calls.

Please log in or register to report this question.

12.

What will happen if a value is returned from a function declared with void return type in C ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: C

The keyed result is a compilation error.

A function declared void promises to return no value. The C standard makes a return statement with an expression in a void function a constraint violation, so the compiler must issue a diagnostic, and C++ compilers and strict C compilers reject it outright.

The value is not printed automatically, since returning a value never prints anything. The problem is caught when the program is compiled, not when it runs, so 'runtime error' is wrong; and the compiler does not silently ignore it.

Please log in or register to report this question.

13.

What is the value returned by the recursive function ackermann(2,3) ?

int ackermann(int i, int j){
if(i= =0) return 2*j;
else if (j= =1) return 2;
else return ackermann(i-1, ackermann(i, j-1));
}

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: A

ackermann(2,3) returns 16.

With i = 1 the function doubles repeatedly: ackermann(1, j) = \(2^{j}\), since ackermann(1,1) = 2 and each step applies \(2 \times\) to the previous value. Now unwind ackermann(2,3).

\[ \begin{aligned} a(2,1) &= 2 \\ a(2,2) &= a(1, a(2,1)) = a(1,2) = 4 \\ a(2,3) &= a(1, a(2,2)) = a(1,4) \\ &= 2^{4} = 16 \end{aligned} \]

Check a(1,4): it calls a(0, a(1,3)), and a(1,3) = 8, so the result is \(2 \times 8 = 16\). Options 20, 25 and 30 do not come from any correct reading of the recursion.

Please log in or register to report this question.

14.

What is the total number of recursive calls/invocations to compute fib(8) using the function ?

int fib(int n){
if (n = =1) return 1;
else if(n= =2) return 1;
else return(fib(n-1)+fib(n-2));
}

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: D

Computing fib(8) takes 41 calls in all.

Let C(n) be the number of invocations for fib(n), counting the call itself. fib(1) and fib(2) make one call each; any larger n makes one call plus the calls for n-1 and n-2.

\[ \begin{aligned} C(n) &= C(n-1) + C(n-2) + 1 \\ C(3) &= 3,\ C(4) = 5,\ C(5) = 9 \\ C(6) &= 15,\ C(7) = 25 \\ C(8) &= 25 + 15 + 1 = 41 \end{aligned} \]

A shortcut: \(C(n) = 2F(n) - 1\), and fib(8) = 21 gives \(2 \times 21 - 1 = 41\). 21 is the value fib(8) returns, not the number of calls, and 13 is fib(7).

Please log in or register to report this question.

15.

The Default Parameter Passing Mechanism is called as

Exam Year(s)

UGC NET - 2012,

Answer: A

The default parameter passing mechanism in languages such as C, C++ and Java is call by value: the value of the actual parameter is copied into the formal parameter, and changes made inside the function do not affect the caller. Call by reference, by address and by name need special syntax or are used in other languages, so they are not the default. The keyed answer is Call by Value.

Please log in or register to report this question.

16.

Match List – I with List – II and select the correct answer using codes given below :

List-IList-II
(a) call by reference(i) Incorrect statement
(b) size of (float);(ii) Function
(c) &(iii) 4
(d) return (a, b);(iv) bitwise AND

Exam Year(s)

UGC NET - 2012,

Answer: C

The matching is a-ii, b-iii, c-iv, d-i. Call by reference is a way of passing arguments to a function, so it goes with function. The operator sizeof(float) gives 4, the number of bytes of a float. The symbol & as a binary operator is the bitwise AND. The statement return (a, b); is an incorrect statement in the sense that a function cannot return two values this way, as the comma operator would give only b. Option (A) pairs call by reference with an incorrect statement. Options (B) and (D) reverse several of the pairs. Only (C) fits all four.

Please log in or register to report this question.

17.

Which of the following is/are the fundamental semantic model(s) of parameter passing ?

Exam Year(s)

UGC NET - 2013,

Answer: D

All of the above is the answer. The three fundamental semantic models of parameter passing are in mode, in which the value passes from the caller into the subprogram, out mode, in which the value passes back to the caller, and in-out mode, in which it passes both ways.

Each of options (A), (B) and (C) names only one of the three, so none of them alone is complete.

Please log in or register to report this question.

18.

When an array is passed as a parameter to a function which of the following statements is correct ?

Exam Year(s)

UGC NET - 2013,

Answer: A

When an array is passed as a parameter to a function in C, what is passed is the address of its first element, so the function can change the values in the original array. The answer is (A).

The array is not copied, so option (B) is wrong, and passing an array is quite legal, so there is neither a compilation error (C) nor a runtime error (D). This is why a function such as one that sorts an array in place needs no return value, whereas the same function would have no effect on a single integer argument, which is passed by value.

Please log in or register to report this question.

19.

What is the output of the following program segment ?

sum(n)
{
if ( n \(\lt\) 1 ) return n;
else return (n + sum(n-1));
}
main()
{
printf("%d", sum(5));
}

Exam Year(s)

UGC NET - 2013,

Answer: C

The function adds n to the sum of the numbers below it until n is less than 1, and then returns n.

\[ \text{sum}(5) = 5 + 4 + 3 + 2 + 1 + \text{sum}(0) \]

\[ \text{sum}(5) = 15 + 0 = 15 \]

The value 10 would be the sum 4 + 3 + 2 + 1, which leaves out the first call, and 16 and 14 do not follow from the recursion. The program prints 15, so option C is correct.

Please log in or register to report this question.

20.

What will be the output of the following statements ?
int a = 5, b = 2, c = 10, i = a \(\gt\) b
Void main ( )
{print f(“hello”); main ( );}

Exam Year(s)

UGC NET - 2013,

Answer: C

The program calls main from inside main with no condition to stop the recursion, so it prints hello again and again, and the output is hello repeated an infinite number of times (until the stack overflows). The values of a, b, c and i do not affect the loop, and the output is not 1, 2 or 10. So infinite number of times is correct.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Functions Questions and Answers || Functions MCQ Questions and Answers || Functions GK Questions and Answers || Functions GK MCQ Questions || Functions Multiple Choice Questions and Answers || Functions GK || GK on Functions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming