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

Set-26 C MCQ

1. What will be the output of the following code?

void my_recursive_function(int n)
{
if(n == 0)
{
printf(“False”);
return;
}
if(n == 1)
{
printf(“True”);
return;
}
if(n%2==0)
my_recursive_function(n/2);
else
{
printf(“False”);
return;
}

}
int main()
{
my_recursive_function(100);
return 0;
}

a) True
b) False
b)compilation error
d)run time error

Answer:b


2. What is the output of the following code?

int cnt = 0;
void my_recursive_function(char *s, int i)
{
if(s[i] == ‘\0’)
return;
if(s[i] == ‘a’ || s[i] == ‘e’ || s[i] == ‘i’ || s[i] == ‘o’ || s[i] == ‘u’)
cnt++;
my_recursive_function(s,i+1);
}
int main()
{
my_recursive_function(“thisisrecursion”,0);
printf(“%d”,cnt);
return 0;
}

a) 6
b) 9
c) 5
d) 10

Answer : a


3. What is the output of the following code?

void my_recursive_function(int *arr, int val, int idx, int len)
{
if(idx == len)
{
printf(“-1”);
return ;
}
if(arr[idx] == val)
{
printf(“%d”,idx);
return;
}
my_recursive_function(arr,val,idx+1,len);
}
int main()
{
int array[10] = {7, 6, 4, 3, 2, 1, 9, 5, 0, 8};
int value = 2;
int len = 10;
my_recursive_function(array, value, 0, len);
return 0;
}

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

Answer : b


4. Recursion is similar to which of the following?

a) Switch Case
b) Loop
c) If-else
d) if elif else

Answer : b


5.What is the output of this C code?

void main()
{
static int x = 3;
x++;
if (x <= 5)
{
printf(“hi”);
main();
}
}

A. Run time error
B. hi
C. infinite hi
D. hihi

Answer : D


6. What is the output of this C code? void main()

{
static int x;
if (x++ < 2)
main();
}

A. Infinite calls to main
B. Run time error
C. Varies
D. main is called twice

Answer : d


7.What will be the output of the program?

#include<stdio.h>
void fun(int);

int main()
{
int a=3;
fun(a);
return 0;
}
void fun(int n)
{
if(n > 0)
{
fun(–n);
printf(“%d,”, n);
fun(–n);
}
}

A. 0, 2, 1, 0,
B. 1, 1, 2, 0,
C. 0, 1, 0, 2,
D. 0, 1, 2, 0,

Answer : d


8. Find output of the following:

#include<stdio.h>
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf(“%d, %d\n”, a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}

A. 4, 4
B. 3, 3
C. 6, 6
D. 12, 12

Answer : C
C MCQ Set-12 Explanation


9. What is the output of this C code?

#include<stdio.h>
int fun(int n)
{
int i, j, sum = 0;
for(i = 1;i<=n;i++)
for(j=i;j<=i;j++)
sum=sum+j;
return(sum);
}

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

A) 55
B) 75
C) 15
D) 225

Answer : A
C MCQ Set-12 Explanation


10. What will be the output of the program?

#include<stdio.h>
int check(int);
int main()
{
int i=45, c;
c = check(i);
printf(“%d\n”, c);
return 0;
}
int check(int ch)
{
if(ch >= 45)
return 100;
else
return 10;
}

A. 100
B. 10
C. 1
D. 0

Answer: A


Spread the love

Leave a Comment

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