NEW
Font size
WorksheetsPSP Module-4
Total questions: 20
Worksheet time: 10mins
What will happen after compiling and running the following code?
main()
{
printf("%p", main);
}
Error
Will make an Infinite loop
Some address will be printed
None of these
Use of functions
Helps to avoid repeating a set of statements many times
Enhances logical clarity of the program
Makes the debugging task easier
All the above
Any C program
Must contain at least one function
Need not contain any function
Needs input data
nothing
What is function?
Functions are block of statement that perform some specific task
Function is the fundamental modular unit. It is usually designed to perform a specific task
Functions are block of code that perform a specific task. It has a name and it is reusable
All of the above
Determine the output
main()
{
int i = abc(10);
printf("%d", --i);
}
int abc(int i)
{
return(i++);
}
10
9
11
Error
In C functions, parameters are always
Passed by value
Passed by reference
Non-pointer variables are passed by value and pointers are passed by reference
Passed by value result
Which of the following is true about return type of functions in C?
Functions can return any type
Functions can return any type except array and functions
Functions can return any type except array, functions and union
Functions can return any type except array, functions, function pointer and union
Output of following program?
void dynamic(int s, ...)
{
printf("%d ", s);
}
int main()
{
dynamic(2, 4, 6, 8);
dynamic(3, 6, 9);
return 0;
}
2 3
Compiler Error
4 3
3 2
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);
}
Compile Time Error
1
0
Runtime Error
What are the types of functions in C Language?
Library Functions
User Defined Functions
Both Library and User Defined
None of the above
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.
Call swap (x, y)
Call swap (&x, &y)
swap(x,y) cannot be used as it does not return any value
swap(x,y) cannot be used as the parameters are passed by value
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);
}
10
4
6
7
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;
}
10
11
12
15
The recursive functions are executed in a......
Parallel
First In First Out Order
Last In First Out Order
Iterative Order
Random Order
The process in which a function calls itself directly or indirectly is called?
Recursion
Type Conversions
Constant
Abstract Classes
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));
}
6
7
8
9
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));}
2
3
6
1
What is the output of func(4);?
int func(int number)
{
if(number <= 0)
return 1;
else
return number * func(number-1);
}
12
24
1
0
What is the output of print(12)?
void print(int n)
{
if (n == 0)
return;
printf("%d", n%2);
print(n/2); }
0011
1100
1001
1000
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;
}
Stack Overflow
3
4
5
