Вы находитесь на странице: 1из 12

TITAN IQ ‘10

Date : 10th March 2010

Code Obfuscation
-Preliminary Round

Team name :

Name Roll No. Contact no.

INSTRUCTIONS:
 Question paper has got 25 questions.

 Question paper has various marks depending on the toughness of the question.

 Duration of the test is 30 minutes.

 ‘Predict the output’ questions may have errors. If so you have to specify the errors and
correct only the part that causes the errors.

 Assume that all the necessary header files are included.

 Star questions carry 4 marks each and will be considered to break ties.

 Questions 5, 6, 10, 13, 18, 20, 21 carry 2 marks each.

 Remaining questions carry 1 mark each.

1
TITAN ’IQ

1.) What number will z in the sample snippet below contain?

int z,x=5,y=-10,a=4,b=2;

z = x++ - --y * b*x / a;

2.) "My salary was increased by 15%!"

Select the statement which will EXACTLY reproduce the line of text above.

i. printf("My salary was increased by 15%!\n");

ii. printf("\"My salary was increased by 15\%!\"\n");

iii. printf("My salary was increased by 15'%'!\n");

iv. printf("\"My salary was increased by 15%%!\"\n");

v. printf("\"My salary was increased by 15'%'!\"\n");

3.) Predict the output. Spot the error if any.

int main(a1,s)int a1;int s;{

int b=1;

if(b==1.0)

printf("Int val equal");

float a=1.1;

if(1.1==a)

printf("float val equal");

printf("Bye :h"); }

4.) Predict the Output ... State Errors if any

reverse(int integer, int Size, int gamma, int k) {

(gamma<Size) ?

printf("%c",(gamma==2)||(gamma==3)||(gamma==9) ?

2
TITAN ’IQ

k++, gamma++, 108 :

*((int*)integer + gamma++ - k)), reverse(integer,Size, gamma, k) : 0;

int main() {

int ele[]= { 72,'e',111,040,0127,0x6F,'r',0x64,041 };

int size = (int)ele;

reverse(size, 12, 0, 0);}

5.) Predict the output. If any error, debug and predict the output.

main(){

int x=5,y=6,a;

a=++x+--y*--x*x++*--x/2;

b=1+++a + a++;

printf("%d %d %d",a,x);

6.) Predict the output. Spot the error if any.

??=include<iostream>

??=include<stdio.h>

??=include<conio.h>

using namespace std;

int main()??<

int a??(??)=??<1,2,3,4,5??>;

cout<<??-a??(2??);

getch();??>

3
TITAN ’IQ

7.) Predict the output. Spot the error if any.

void return_(int no, int last, int start) {

printf("%d ",*((int*)no+last));

last++;

if (last < start)

return_(no, last, start);

void main() {

int a[]={0,1,2,3,4,5,6,7,8,9};

return_((int)a, (0,3)?5:3 , sizeof(a)/4-2);

8.) Predict the output. Spot the error if any.

#define WORLD main()

#define HELLO int

HELLO WORLD ??<

char ch[]="hello";

if(ch<:2:>==121??!??!ch<:1:>==101)

<%cout<<"hai";%>

else

cout<<"bye";

getch();??>

9.) Predict the output. Spot the error if any.

print(int m, int t, int c) {

((t / m) <= 1) ? print(m,t+1,c) : !(t % m) ? print(m,t+1, t % m) :

4
TITAN ’IQ

((t % m)==(t / m) && !c) ? (printf("%d\t",(t / m)), print(m,t+1,c)) :

((t % m)> 1 && (t % m) < (t / m)) ? print(m,t+1,c + !((t / m) % (t % m))) :

(t < m * m) ? print(m,t+1,c) : 0;

int main(void) {

print(10,0,0);}

10.) Predict the output when i.) a=1 ii.) a=2 iii.) a=3.

main(){

int a;

char *M;

scanf(M="%d",&a);

cout<<a<<" "<<M<<endl;

switch(a) {

default:

cout<<"hello1"<<endl;

case 1:

if(a==1) {

cout<<"1"<<endl;

break;

cout<<"2"<<endl;

cout<<"3"<<endl

case 2:

cout<<"hello";

cout<<"bye"<<endl;}

5
TITAN ’IQ

11.) Predict the output. Spot the error if any.

void display(){

printf("TITAN");

return;

int main(){

void (*print)();

print=display;

print();

(*print)();

return 0;

12.) Predict the output. Spot the error if any.

int bigger(int u, int v) {

int shift;

if (u == 0 || v == 0)

return u | v;

for (shift = 0; ((u | v) & 1) == 0; ++shift) {

u >>= 1;

v >>= 1;

while ((u & 1) == 0)

u >>= 1;

do {

6
TITAN ’IQ

while ((v & 1) == 0)

v >>= 1;

if (u < v) {

v -= u;

} else {

int diff = u - v;

u = v;

v = diff;

v >>= 1;

} while (v != 0);

return u << shift;

void main(){

int a=0;

int b=3,c;

c=++a,a++,b+=2;

printf("%d ",bigger(c,b));

13.) Debug the given program and predict the output.

class N

int a;

public:

N() {

N(5); }

7
TITAN ’IQ

N(int a) {

a=this.a;}

void print() {

cout<<"A: "<<a<<endl; }

};

int main(){

N n,n1(10);

n.print();

n1.print();}

14.) Predict the output of the following snippet in i)C & ii)C++. If you feel the compiler might throw any
errors or warnings, mention them.

int fn()

int a;

char ch[]="ajsjas";

a=ch;

printf(”hello world”);

15.) Predict the output.If you feel the compiler might throw any error or warning, mention it.
int main()

int a=5,b=10;

if(10=b)

printf("hello");

return 0;

8
TITAN ’IQ

printf(" world!!!");

16.) Predict the output. Spot the error if any.

#define _ F-->00 || F-OO--;


long F=01,OO=00;
main(){F_OO();printf("%1.2f\n", 4.*-F/OO/OO);getch();}F_OO(){
_-_-_-_
_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_
_-_-_-_

17.) Predict the output. Spot the error if any.

main(argc, argv)

int argc;

char **argv;

while (*argv != argv[1] && (*argv = argv[1]) && (argc = 0) || (*++argv

&& (**argv && ((++argc)[*argv] && (**argv <= argc[*argv] ||

(**argv += argc[*argv] -= **argv = argc[*argv] - **argv)) &&

--argv || putchar(**argv) && ++*argv--) || putchar(10))))

9
TITAN ’IQ

18.) Predict the output. Spot the error if any.

void _(int O, int _O, char _0) {

for (; O<_O; ++O) {

printf("%c ",_0);

_0++;

int main() {

_('O','o','O');

return 0;

19.) Predict the output. Spot the error if any.

int main() {

int a;

a=1,2;

cout<<"a:"<<a<<endl;

int b, c;

a=(b=2, c=3, a<0) ? (b+=3, b-1) : (c+=b, c+2);

cout<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl;

return 0;

20.) Predict the output. Spot the error if any.

int main() {

int a=1,b=2,x=5,y=4;

10
TITAN ’IQ

a -= b;

a &= (~a) >> 31;

a += b;

x -= y;

x &= x >> 31;

x += y;

printf("a:%d b:%d x:%d y:%d",a,b,x,y);}

21.) Predict the output. Spot the error if any.

int main(){

int val[]={0,1,2,3,4,5,6,7,8,9,10};

2*3*4*5/100;

"hello world";

1,val[4]*=10;

val[0]&&++val[3]||++val[1];

int *ptr=val;

printf("%d %d %d %d %d %d %d %d" ,val+1,(*(int *)ptr)--


,++*ptr,*ptr++,*++ptr+1,++*ptr+1,*ptr+4,*(4+ptr));

22.) Predict the output. Spot the error if any.

void main()

int matrix[2][3]={{1,2,3},{4,5,6}};

printf("%d %d %d\n",*(*(matrix)),*(*(matrix+1)+2),*(*matrix+1));

printf("%d %d %d",*(matrix[0]+2),*(matrix[1]+1),*(*(matrix+1)));

11
TITAN ’IQ

23.) Predict the output. Spot the error if any.

struct A {

int b;

struct A {

int b;

struct B *nextB;

}tempB;

struct A nextB;

}tempB;

int main() {

tempB.nextB.b=5;

printf("%d",tempB.nextB.b); }

24.) Predict the output. Spot the error if any.

void main()

int a=2,b=3,c=4,d=5,e;

if (e=(a & b | c ^ d))

printf("%d",e);

25.) Predict the output. Spot the error if any.

int main(){

unsigned x=80,y=5,z;

z=x<<y; printf("hello!!! %#x %#x"+5,x,z);;}

12

Вам также может понравиться