C MCQ Set-6 : Multiple Choice Questions in C Set-6

Set-26 C MCQ

1. Find output of the following.

int fun ( int n, int *fp )
{
int t, f;

if ( n <= 1 )
{
*fp = 1;
return 1;
}
t = fun ( n-1, fp );
f = t + *fp;
*fp = t;
return f;
}

int main()
{
int x = 15;
printf(“%d\n”,fun(5, &x));
return 0;
}

a) 8
b) 7
c) 6
d) 5

Ans:A


2. Find output of the following.

int fun(int i)
{
if ( i%2 ) return (i++);
else return fun(fun( i – 1 ));
}

int main()
{
printf(” %d “, fun(200));
getchar();
return 0;
}

a)198
b)199
c)111
d)000

Ans:b


3. Find output of the following.

void fun(int n)
{
if(n > 0)
{
fun(n-1);
printf(“%d “, n);
fun(n-1);
}
}

int main()
{
fun(4);
return 0;
}

a)1 2 2 3 2 1 4 1 2 1 3 1 2 1
b)1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
c)1 3 1 2 1 2 1 4 1 2 1 3 1 2 1
d)1 2 2 3 1 2 1 2 1 2 1 3 1 2 1

Ans:b


4. Find output of the following.

int fun(int a, int b)
{
if (b == 0)
return 0;
if (b % 2 == 0)
return fun(a+a, b/2);

return fun(a+a, b/2) + a;
}

int main()
{
printf(“%d”, fun(4, 3));
getchar();
return 0;
}

a)12
b)11
c)10
d)13

Ans:a


5. Find output of the following.

#include<stdio.h>
int fun(int a, int b)
{
if (b == 0)
return 1;
if (b % 2 == 0)
return fun(a*a, b/2);

return fun(a*a, b/2)*a;
}

int main()
{
printf(“%d”, fun(4, 3));
getchar();
return 0;
}

a)64
b)63
c)65
d)60

Ans:a


6. Find output of the following.

#include <stdio.h>
int fun(int n)
{
if (n > 100)
return n – 10;
return fun(fun(n+11));
}

int main()
{
printf(” %d “, fun(99));
getchar();
return 0;
}

a)90
b)91
c)89
d)92

Ans:b


7. Find output of the following.

int fun1(int x, int y)
{
if(x == 0)
return y;
else
return fun1(x – 1, x + y);
}
main()
{
printf(“%d”,fun1(2,3));
}

a)6
b)7
c)8
d)5

Ans:a


8. Find output of the following.

int fun1(int n)
{
if(n == 1)
return 0;
else
return 1 + fun1(n/2);
}
main()
{
printf(“%d”,fun1(8));
}

a)3
b)4
c)5
d)2

Ans:a


9. Find output of the following.

#include <stdio.h>
int main()
{
int fun(int);
int i = fun(10);
printf(“%d\n”, –i);
return 0;
}
int fun(int i)
{
return (i++);
}

A. 9
B. 10
C. 11
D. 8

Ans:a


10. Find output of the following.

void fun(int x)
{
if(x > 0)
{
fun(–x);
printf(“%d\t”, x);
fun(–x);
}
}

int main()
{
int a = 4;
fun(a);
getchar();
return 0;
}

a)1 0 2 3 0 0 1
b)0 1 2 0 3 0 1
c)1 0 2 3 0 0 3
d)1 1 2 3 0 0 1

Ans:b


11. Find output of the following.

#include <stdio.h>
int fun(int a[],int n)
{
int x;
if(n == 1)
return a[0];
else
x = fun(a, n-1);
if(x > a[n-1])
return x;
else
return a[n-1];
}

int main()
{
int arr[] = {12, 10, 30, 50, 100};
printf(” %d “, fun(arr, 5));
getchar();
return 0;
}

a)100
b)001
c)101
d)000

Ans:a


12. What will be the output of the program, if a short int is 2 bytes wide?

# include <stdio.h>
int main()
{
short int i = 0;
for(i<=5 && i>=-1; ++i; i>0)
printf(“%u,”, i);
return 0;
}

A. 1,2,3,4,… ,65535
B. Expression syntax error
C. No output
D. 0, 1, 2, 3, 4, 5

Ans: A
C MCQ Set-6 Explanation


13. Which of the following is pre-test loop?

(A) for loop
(B) while loop
(C) do-while loop
(D) for and while loop

Ans: D


14. What will bw output of folowing code?

#include<stdio.h>
int main()
{
int i;
for (i = 1; i != 10; i += 2)
printf(” Hello “);
return 0;
}

(A) Hello Hello Hello Hello Hello
(B) Hello Hello Hello …. infinite times
(C) Hello Hello Hello Hello
(D) Hello Hello Hello Hello Hello Hello

Ans: B
C MCQ Set-6 Explanation


15. What will be output of following c code?

#include<stdio.h>
void main( )
{
char *str = “”;
do
{
printf(“hello”);
}
while (str);
}

A) Nothing
B) Run time error
C) Varies
D) Hello is printed infinite times

Ans: D
C MCQ Set-6 Explanation


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *