C Functions Questions 2

Hello PrepSter,

If you find any errors in the quiz below kindly comment in the comment section and we will make it our priority to fix it.

Also if you have a better of the solution to the questions, please do comment them below and if we find it better than ours, we will post it in our website.

Question 1

Time: 00:00:00
What is the output of the code given below ?
#include<stdio.h>
void loo(int n, int sum)
{
int d = 0, r = 0;
if (n == 0) return;
d = n % 10;
r = n / 10;
sum = sum + d;
loo (r, sum);
printf ("%d,", d);
}
int main ()
{
int num = 1998, sum = 0;
loo (num, sum);
printf ("%d ", sum);
return 0;
}

8,9,9,1,27

8,9,9,1,27

8,9,9,1,0

8,9,9,1,0

1,9,9,8,27

1,9,9,8,27

1,9,9,8,0

1,9,9,8,0

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
This code given below runs perfectly.

But what happens if we delete the code between //from here //to here ?
#include<stdio.h>
//from here
int fun (int);
//to here
int main()
{

int num2, num3;
num3 = fun(num2);
}

int fun(int num)
{
printf("Ye");
return num;
}

The code will be compiled and Ye will be printed.

The code will be compiled and Ye will be printed.

The code will be show warnings but ye will be printed.

The code will be show warnings but ye will be printed.

The code will not be compiled and nothing will be printed.

The code will not be compiled and nothing will be printed.

The code will show warnings and there will be unintended output.

The code will show warnings and there will be unintended output.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
What happens if the call the  following program.
void swap (int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
}

Function simply swaps number x and y for he main function.

Function simply swaps number x and y for he main function.

The number are swapped in this function but in main he numbers doesn't swap because there is no return type for the function swap.

The number are swapped in this function but in main he numbers doesn't swap because there is no return type for the function swap.

The number swapped inside this function but since hey are passed by value the value passed to the function swap doesn't change the value in main.

The number swapped inside this function but since hey are passed by value the value passed to the function swap doesn't change the value in main.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
What is the expected output of he following C code ?
#include<stdio.h>
int plus(int i)
{
static int fix = 0;
fix = fix + i;
return (fix);
}
void main()
{
int i,j;
for (i = 0; i <=4; i++)
j = plus(i);
printf("%d",j);
}

4

4

5

5

9

9

10

10

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
What is the expected output for he program below ?
#include <stdio.h>
int main()
{
printf("PrepInsta");
main();
return 0;
}

Compiler error.

Compiler error.

Infinite loop that prints PrepInsta.

Infinite loop that prints PrepInsta.

PrepInsta will be printed 2,147,483,647 times i.e the hight value of int .

PrepInsta will be printed 2,147,483,647 times i.e the hight value of int .

PrepInsta will be printed until there is a stack overflow.

PrepInsta will be printed until there is a stack overflow.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
Are these two function declaration similar ?
/* First function Declaration*/
int (*fun1)(int), (*fun2)(int);

/* Second function Declaration*/
typedef int (*fun)(int);
fun fun1, fun2;

Yes, they are same.

Yes, they are same.

No, they are not same.

No, they are not same.

They are same but tydef is global therefore local function may not able o access it

They are same but tydef is global therefore local function may not able o access it

We can't have a typedef for a pointer to a function.

We can't have a typedef for a pointer to a function.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
What will be printed by the following program ?
#include <stdio.h>
void rep1 (int x, int y)
{
int z;
z=x; x=y; y=z;
}
void rep2 (int *x, int *y)
{
int z;
z=*x; *x=*y;*y=z;
}
int main()
{
int x=1, y=2, z=3;
rep1(x, y);
rep2(&y, &z);
printf ("%d", z-x-y);
return 0;
}

-2

-2

1

1

2

2

-1

-1

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
What is the correct output of the following program ?
#include<stdio.h>
int fun(int val)
{
val=0;
printf("%d",val);
return 0;
}
int main()
{
fun;
return 0;
}

0 will be printed.

0 will be printed.

Some garbage value will be printed.

Some garbage value will be printed.

Nothing will be printed.

Nothing will be printed.

Compilation error.

Compilation error.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
What is the output of the following program ?
#include <stdio.h>
int dcr()
{
static int i = 22;
return i--;
}

int main()
{
for(dcr(); dcr(); dcr())
printf("%d ", dcr());
return 0;
}

20 20 20 20 20 infinite times.

20 20 20 20 20 infinite times.

22 18 14 10 6 4 2 0

22 18 14 10 6 4 2 0

21 18 15 12 9 6 3 0

21 18 15 12 9 6 3 0

20 17 14 11 8 5 2

20 17 14 11 8 5 2

19 16 13 10 7 4 1

19 16 13 10 7 4 1

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
Select the correct output of the following program.
#include <stdio.h>
int f1 (int a);
int f2 (int b);
void main()
{
int a = 10, b = 5, i;
for (i = 1; i <= 2; ++i)
{
b += f1(a) + f2(a);
printf ("%d ", b);
}
}

f1(int a)
{
int b;
b = f2(a);
return (b);
}

f2(int a)
{
static int b = 10;
b++;
return (b+a);
}

48 95

48 95

47 93

47 93

48

48

47

47

43 85

43 85

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]