wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PSP Module-4

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What will happen after compiling and running the following code?

main()

{

printf("%p", main);

}

a)

Error

b)

Will make an Infinite loop

c)

Some address will be printed

d)

None of these

2.

Use of functions

a)

Helps to avoid repeating a set of statements many times

b)

Enhances logical clarity of the program

c)

Makes the debugging task easier

d)

All the above

3.

Any C program

a)

Must contain at least one function

b)

Need not contain any function

c)

Needs input data

d)

nothing

4.

What is function?

a)

Functions are block of statement that perform some specific task

b)

Function is the fundamental modular unit. It is usually designed to perform a specific task

c)

Functions are block of code that perform a specific task. It has a name and it is reusable

d)

All of the above

5.

Determine the output

main()

{

int i = abc(10);

printf("%d", --i);

}

int abc(int i)

{

return(i++);

}

a)

10

b)

9

c)

11

d)

Error

6.

In C functions, parameters are always 

a)

Passed by value

b)

Passed by reference

c)

Non-pointer variables are passed by value and pointers are passed by reference

d)

Passed by value result

7.

Which of the following is true about return type of functions in C?

a)

Functions can return any type

b)

Functions can return any type except array and functions

c)

Functions can return any type except array, functions and union

d)

Functions can return any type except array, functions, function pointer and union

8.

Output of following program?

void dynamic(int s, ...)

{

    printf("%d ", s);

}

 

int main()

{

    dynamic(2, 4, 6, 8);

    dynamic(3, 6, 9);

    return 0;

}

a)

2 3

b)

Compiler Error

c)

4 3

d)

3 2

9.

if we run this code so what will be the output:

void foo()

{

return 1;

}

void main()

{

int x = 0;

x = foo();

printf("%d", x);

}

a)

Compile Time Error

b)

1

c)

0

d)

Runtime Error

10.

What are the types of functions in C Language?

a)

Library Functions

b)

User Defined Functions

c)

Both Library and User Defined

d)

None of the above

11.

Consider the following C function

void swap (int a, int b)

{

   int temp;

   temp = a;

   a = b;

   b = temp;

}

In order to exchange the values of two variables x and y.

a)

Call swap (x, y)

b)

Call swap (&x, &y)

c)

swap(x,y) cannot be used as it does not return any value

d)

swap(x,y) cannot be used as the parameters are passed by value

12.

The value of j at the end of the execution of the following C program.

int incr(int i)

{

   static int count = 0;

   count = count + i;

   return (count);

}

main()

{

   int i,j;

   for (i = 0; i <=4; i++)

      j = incr(i);

}

a)

10

b)

4

c)

6

d)

7

13.

What is the output of C program with recursive function?

int sum(int x)

{   

int k = 1   

if(x <= 1)     

return 1;   

k = x + sum(x - 1);     

return k;

}

a)

10

b)

11

c)

12

d)

15

14.

The recursive functions are executed in a......

a)

Parallel

b)

First In First Out Order

c)

Last In First Out Order

d)

Iterative Order

e)

Random Order

15.

The process in which a function calls itself directly or indirectly is called?

a)

Recursion

b)

Type Conversions

c)

Constant

d)

Abstract Classes

16.

What will be output for the following code?

main()

{

int num=5;

int fun(int num);

printf(""%d"",fun(num));

}

int fun(int num)

{

if(num>0)

return(num+fun(num-2));

}

a)

6

b)

7

c)

8

d)

9

17.

What is the output?

int mul(int);

int main()

{   

int b;   

b = mul(3);   

printf("%d", b);

}

int mul(int x){   

if(x<=1)     

return 1;   

return (x * mul(x-1));}

a)

2

b)

3

c)

6

d)

1

18.

What is the output of func(4);?

int func(int number) 

{     

if(number <= 0)         

return 1;                                 

else         

return number * func(number-1);   

}

a)

12

b)

24

c)

1

d)

0

19.

What is the output of print(12)?

void print(int n)

{    

if (n == 0)        

return;    

printf("%d", n%2);    

print(n/2); }

a)

0011

b)

1100

c)

1001

d)

1000

20.

Predict the output of following program

int f(int n)

{

    if(n <= 1)

        return 1;

    if(n%2 == 0)

        return f(n/2);

    return f(n/2) + f(n/2+1);

}

 

 

int main()

{

    printf("%d", f(11));

    return 0;

}

a)

Stack Overflow

b)

3

c)

4

d)

5