Level1 Programming Test2
Level1 Programming Test2
Which one of the choices given below would be printed when the following program is
executed?
#include
int a1[]= {6, 7, 8, 18, 34, 67};
int a2[] = {23, 56, 28, 29};
int a3[] = {-12, 27, -31};
int *x= {al, a2, a3};
void print(int *a[])
{
printf("%d,",a[0][2]);
printf("%d,”,*a[2]);
printf("%d,", ++a[0]);
printf(“%d,”,*(++a)[0]);
printf("%d\n",a[-1][+1]);
}
main()
{
print(x);
}
8, -12, 7, 23, 8
8, 8, 7, 23, 7
-12, -12, 27, -31, 23
-12, -12, 27, -31, 56
Yes
No
2
Error
DIRECTIONS for the question: Mark the best option:
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);
}
int main() {
f(&I, &j)
printf("%d %d\n", i,j);
return 0;
}
2 2
2 1
0 1
0 2
5
8
9
20
DIRECTIONS for the question: Mark the best option:
Consider the following recursive C function that takes two arguments.
unsignedint foo(unsigned int n, unsigned int r)
{
if(n>O) return (n%r+foo(n/r,r));
else return 0;
}
What is the return value of the function foo when it is called as foo (513,2)?
9
8
5
2
Runtime error
20
Some random number
Both Option A and C
A B
U V
A B
V W
A B
U V
U V
V W
A B
U V
V W
U V
4
5
1 Index out of bounds 1
5 Index out of bounds 0
What is the return value of the function foo when it is called as foo(345,10) ?
345
12
5
3
dlrow
Null string
dlrld
worow
DIRECTIONS for the question: Mark the best option:
How many # 's do the following statements print?
for (int m=0, n=10; n-m > 5; ++m, - -n)
System.out.print(" # ");
0
1
2
3
jungle, n, 8, nclastor
etter, u, 6, ungle
cetter, k, 6, jungle
etter, u, 8, ncestor
5, 5
5, 4
4, 5
4, 4
23
17
34
26
ad
be
cf
ac
eb
cf
ae
dc
bf
Which one of the following options represents the correct output of the program for the two
parameter passing mechanisms?
Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70
outputs
123
0123
an unpredictable garbage value
291
43 80
42 74
33 37
32 32
2,3
2, 4
3, 2
3, 3