Question 1
What is the output of the following program ?
main (){
int x = 2, y = 5;
if(x < y) return (x = x + y);
else printf ("z1");
printf("z2");
z2
z1z2
Compilation error
None of these
Question 2
Consider the following program:
int f(int *p, int n)
{
if (n <= 1) return 0;
else return max(f(p+1,n-1),p[0]-p[1]);
}
int main()
{
int a[] = {3,5,2,6,4};
printf("%d", f(a,5));
}
Note: max(x,y) returns the maximum of x and y. The value printed by this program is
2
3
4
5
Question 3
Given a boolean function f (x1, x2, ..., xn), which of the following equations is NOT true
f(x1, x2, …, xn) = x1'f(x1, x2, …, xn) + x1f(x1, x2, …, xn)
f(x1, x2, ..., xn) = x2f(x1, x2, …, xn) + x2'f(x1, x2, …, xn)
f(x1, x2, ..., xn) = xn'f(x1, x2, …, 0) + xnf(x1, x2, …,1)
f(x1, x2, ..., xn) = f(0, x2, …, xn) + f(1, x2, ..., xn)
Question 4
Consider the following program written in pseudo-code. Assume that x and y are integers.
Count (x, y) {
if (y !=1 ) {
if (x !=1) {
print("*");
Count (x/2, y);
}
else {
y=y-1;
Count (1024, y);
}
}
}
The number of times that the print statement is executed by the call Count(1024, 1024) is _______ .
Note - This was Numerical Type question.
10230
10
1023
23010
Question 5
Consider the function
int fun(x: integer)
{
If x > 100 then fun = x – 10;
else
fun = fun(fun(x + 11));
}
For the input x = 95, the function will return
89
90
91
92
Question 6
Consider the function
int func(int num) {
int count = 0;
while(num) {
count++;
num >>= 1;
}
return(count) ;
}
For func(435) the value returned is
9
8
0
10
Question 7
Consider the following C function
void swap ( int x, int y )
{
int tmp;
tmp = x;
x= y;
y = tmp;
}
In order to exchange the values of two variables a and b:
Call swap (a, b)
Call swap (&a, &b)
swap(a, b) cannot be used as it does not return any value
swap(a, b) cannot be used as the parameters passed by value
Question 8
Question 9
Consider the following C code. #include
#include
void main()
{
double pi = 3.1415926535;
int a = 1;
int i;
for(i=0; i < 3; i++)
if(a = cos(pi * i/2) )
printf("%d ",1);
else printf("%d ", 0);
}
What would the program print?
000
010
101
111
Question 10
Consider the following C function:
int f(int n)
{
static int i = 1;
if(n >= 5) return n;
n = n+i;
i++;
return f(n);
}
The value returned by f(1) is
5
6
7
8
There are 41 questions to complete.