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

Functions Questions and Answers

11.

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.

12.

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.

13.

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.

14.

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.

15.

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.

Answer: A

Correct answer: Declared within the scope of a block, usually a function

An automatic variable is one declared inside a block. It comes into existence when the block is entered and disappears when it is left. Declaring it outside all functions would make it static; writing auto is optional, since it is the default.

Please log in or register to report this question.

Answer: D

Correct answer: Both (a) and (b)

An automatic variable is visible from its declaration to the end of the block that contains it, and that includes any blocks nested inside - unless one of them declares another variable of the same name, which shadows it.

Please log in or register to report this question.

18.

Functions can be called either by value or reference

Answer: A

Correct answer: True

C passes everything by value, but passing a pointer by value gives the function the caller’s address and so the effect of call by reference. Both styles are therefore available, which is why arrays - whose names decay to pointers - behave as though passed by reference.

Please log in or register to report this question.

19.

What is the output of the below code snippet?

#include <stdio.h>

main() 
{
   unsigned x = 5, y=&x, *p = y+0; 

   printf("%u",*p);
}

 

Answer: D

Correct answer: 5

y holds the address of x, and p is set to that same address, so *p is x itself - 5. (The code stores an address in an unsigned int, which is poor practice and provokes warnings; it happens to work only where a pointer and an unsigned int are the same width.)

Please log in or register to report this question.

20.

What is the output of this C code?
 

void m();
void n()
{
m();
}
void main()
{
void m()
{
printf("hi");
}
}

 

Answer: B

Correct answer: Compile time error

Two faults. Standard C does not allow a function to be defined inside another, and m is defined inside main here. And n, which calls m, is never called at all - so even if it compiled, nothing would be printed.

Please log in or register to report this question.

Loading…
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