Question 1 |
What is printed by the following ANSI C program?
ASCII encoding for relevant characters is given below

#include < stdio.h >
int main(int argc, char *argv[]){
char a = 'P';
char b = 'x';
char c = (a & b) + '*';
char d = (a | b) - '-';
char e = (a ^ b) + '+';
printf("%c %c %c \n", c, d, e);
return 0;
}
ASCII encoding for relevant characters is given below

z K S | |
122 75 83 | |
* - + | |
P x + |
Question 1 Explanation:
Question 2 |
What is printed by the following ANSI C program?
#include < stdio.h >
int main(int argc, char *argv[])
{
int a[3][3][3] =
{{1, 2, 3, 4, 5, 6, 7, 8, 9},
{10, 11, 12, 13, 14, 15, 16, 17, 18},
{19, 20, 21, 22, 23, 24, 25, 26, 27}};
int i = 0, j = 0, k = 0;
for( i = 0; i < 3; i++ ){
for(k = 0; k < 3; k++ )
printf("%d ", a[i][j][k]);
printf(" \n");
}
return 0;
}
1 2 3
10 11 12 19 20 21 | |
1 4 7 10 13 16 19 22 25 | |
1 2 3
4 5 6 7 8 9 | |
1 2 3
13 14 15 25 26 27 |
Question 2 Explanation:
Question 3 |
What is printed by the following ANSI C program?
#include < stdio.h >
int main(int argc, char *argv[])
{
int x = 1, z[2] = {10, 11};
int *p=NULL; p=&x;
*p=10;
p =&z[1];
*(&z[0]+1)+=3;
printf("%d, %d, %d \n",x,z[0],z[1]); return 0;
}
1, 10, 11 | |
1, 10, 14 | |
10, 14, 11 | |
10, 10, 14 |
Question 3 Explanation:
Question 4 |
Consider the following ANSI C program
#include < stdio.h >
int foo(int x, int y, int q)
{
if ((x < = 0) && (y < = 0))
return q;
if (x < = 0)
return foo(x, y-q, q);
if (y < = 0)
return foo(x-q, y, q);
return foo(x, y-q, q) + foo(x-q, y, q);
}
int main( )
{
int r = foo(15, 15, 10);
printf("%d", r);
return 0;
}
The output of the program upon execution is ____10 | |
60 | |
180 | |
220 |
Question 4 Explanation:
Question 5 |
Consider the following ANSI C code segment:
z=x + 3 + y-> f1 + y-> f2;
for (i = 0; i < 200; i = i + 2)
{
if (z > i)
{
p = p + x + 3;
q = q + y-> f1;
} else
{
p = p + y-> f2;
q = q + x + 3;
}
}
Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and the dereference operations (of the form y -> f1 or y -> f2) in the optimized code, respectively, are:403 and 102 | |
203 and 2 | |
303 and 102 | |
303 and 2 |
Question 5 Explanation:
Question 6 |
Consider the following ANSI C function:
int SomeFunction (int x, int y)
{
if ((x==1) || (y==1)) return 1;
if (x==y) return x;
if (x > y) return SomeFunction(x-y, y);
if (y > x) return SomeFunction (x, y-x);
}
The value returned by SomeFunction(15, 255) is __________17 | |
15 | |
255 | |
5 |
Question 6 Explanation:
Question 7 |
Consider the following ANSI C program.
#include < stdio.h >
int main( )
{
int arr[4][5];
int i, j;
for (i=0; i < 4; i++)
{
for (j=0; j < 5; j++)
{
arr[i][j] = 10 * i + j;
}
}
printf("%d", *(arr[1]+9));
return 0;
}
What is the output of the above program?14 | |
20 | |
24 | |
30 |
Question 7 Explanation:
Question 8 |
Consider the following ANSI C function:
int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex=1; loopIndex<=n-1; loopIndex++)
total=x*total +Y[loopIndex];
return total;
}
Let Z be an array of 10 elements with Z[i]=1, for all i such that 0\leq i \leq 9. The value returned by SimpleFunction(Z,10,2) is __________1023 | |
511 | |
255 | |
2047 |
Question 8 Explanation:
Question 9 |
Consider the following ANSI C program.
#include < stdio.h >
int main()
{
int i, j, count;
count=0;
i=0;
for (j=-3; j < =3; j++)
{
if (( j > = 0) && (i++))
count = count + j;
}
count = count +i;
printf("%d", count);
return 0;
}
Which one of the following options is correct?The program will not compile successfully | |
The program will compile successfully and output 10 when executed | |
The program will compile successfully and output 8 when executed | |
The program will compile successfully and output 13 when executed |
Question 9 Explanation:
Question 10 |
In the following procedure
Integer procedure P(X,Y);
Integer X,Y;
value x;
begin
K=5;
L=8;
P=x+y;
end
X is called by value and Y is called by name. If the procedure were invoked by the following program fragment K=0;
L=0;
Z=P(K,L);
then the value of Z will be set equal to5 | |
8 | |
13 | |
0 |
Question 10 Explanation:
There are 10 questions to complete.