Você está na página 1de 4

Assumptions

1. The generic function print() sends its arguments to the default output stream
2. The given blocks of code are a part of a class (Java, C++) and a file in C.
3. Print ( ) always prints with a new line.

Section 2: Technical

1) What will be the result of the following code?

int i;
for(i = 0; i <= 2; i++)
print("Hi");

2) What will be the result of the following code?

int i;
for(i = 1; i < 5; ++i)
{
if (i == 3)
continue;
else
print(i);
}

3) What will be the result of the following code?

int i;
switch(i = 0)
{
case 0 : i++;
case 1 : i += 2;
case 2 : ++i;
}
print(i++);

4) What will be the result of the following code?

int m, n;
for (m = 0; m < 3; ++m)
{
n = (m % 2 == 0) ? m : m + 2;
print(n);
}

Copyright© 2010 HirePro Consulting Private Limited. All rights reserved.


Page 1 of 4
5) What will be the result of the following code?

int sum, index;


sum = 1;
index = 9;
do
{
index = index - 1;
sum = 2 * sum;
}
while (index > 9);
print(sum);

6) What will be the result of the following code?

int a = 4, b = 0;
if (a > 5)
{
b = 4;
}
else
if (a < 10)
{
b = 3;
}
else
if (a < 5)
{
b = 2;
}
else
{
b = 1;
}
print(b);

7) What will be the result of the following code?

int i = 6720, j = 4;
while((i % j) == 0)
{
i = i / j;
j = j + 1;
}
print(j);

Copyright© 2010 HirePro Consulting Private Limited. All rights reserved.


Page 2 of 4
8) What will be the return value on calling the function checksum(5)?

int checksum(int n)
{
int c;
if(n == 1)
return(1);
else
c = n * checksum(n - 1);
return(c);
}

9) What will be the result of the following code?

int i, x;
for(i = 1; i <= 5; i++)
{
x = i * i;
print(x);
}

10) What will be the result of the following code?

int res;
res = (64 >> (2 + 1 - 2)) | (1 << 2);
print(res);

11) What will be the result of the following code?

int x = 3;
if (2 > x)
print("First");
else
print("Second");
if (2 > x)
print("Third");
print("Fourth");
print("Fifth");

12) What will be the result of the following code?

int a = 1;
while (a <= 1)
{
if (a % 2 == 0)
print(a++);
else
print(++a);
}
print(a + 10);

Copyright© 2010 HirePro Consulting Private Limited. All rights reserved.


Page 3 of 4
13) What will be the result of the following code?

int count = 5;
while (--count + 1 <= 5)
{
print(count);
if(count == 0)
break;

14) What will be the result of the following code?

int m, n, p;
for (m = 0; m < 3; m++)
{
for (n = 0; n < 3; n++)
{
for (p = 0; p < 3; p++)
{
if ((m + n + p) == 2 && m==0 && n==0)
{
print(m);
print(n);
print(p);
}
}
}
}

15) Identify if the following statement is True/False.

A function may have any number of return statements each returning different values of
different data types.

Copyright© 2010 HirePro Consulting Private Limited. All rights reserved.


Page 4 of 4