Time: 60 minutes
Question .No: 30
Allowed: pencil + a piece of paper.
1. Given variable declaration below:
int x,y;
int *a, *b;
Which is wrong statement?
a. a=&x;
b. b=&y;
c. b=&a;
d. *b=*a;
2. Given a short code:
int i=1,j=2;
for(;i<5;i++)
i*=j++;
The given code above is:
a. Wrong syntax
b. i=5, j=4
c. i=10, j=4
d. Three answers above are wrong.
3. Given a short code:
int x[]={0x4161}
char *p1, *p2;
p1=(char*) x;
p2=p1+1;
printf(“%c %d”,*p1, *p2);
Result:
a. A 97
b. a 65
c. A 98
d. a 66
4. Given a short code:
int x=1,y=2;
while(x<=10)
{
x++;
if (x==6)
break;
y+=++x;
}
printf(“%d %d”,x,y);
Result:
a. 6 10
b. 11 37
c. 12 40
d. Three answers above are wrong.
5. Given a short code:
int x=1,y=2;
while(x<=10)
{
x++;
if (x==6);
y+=++x;
}
printf(“%d %d”,x,y);
Result:
a. 6 10
b. 11 37
c. 12 40
d. Three answers above are wrong.
6. Given a short code:
int x=1,y=2;
while(x<=10)
{
x++;
if (x==6)
continue;
y+=++x;
}
printf(“%d %d”,x,y);
Result:
a. 6 10
b. 11 37
c. 12 40
d. Three answers above are wrong.
7. Given a short code:
int i=1,j=0;
for(i=1;i<10;i+=2)
for(;i<8;i++)
j+=i;
printf(“%d %d”,i,j);
Result:
a. 10 28
b. 19 81
c. 11 0
d. Three answers above are wrong.
8. Given a short code:
int i=1,j=0;
for(i=1;i<10;i+=2);
for(;i<8;i++)
j+=i;
printf(“%d %d”,i,j);
Result:
a. 10 28
b. 19 81
c. 11 0
d. Three answers above are wrong.
9. Given a short code:
int i=1,j=0;
if (i>j);
if (i<5)
i+=3;
else
i+=2;
Result of i:
a. 1
b. 2
c. 3
d. 4
Given a short code( is used for 10,11,12,13,14,15):
#include<stdio.h>
double a,b;
void f1(int a);
int f2(int a);
void f1(int a)
{
int s, i;
for(s=i=0; i<=a; s+=++i)
i+=2;
printf(“%d”,s);
}
int f2(int a)
{
int i;
for(i=2;a%i;i++);
printf (“%d”, i);
if (i==a)
return a;
else
return a/i;
}
10. Invoke f1(15)
a. Print 57
b. Print 63
c. Print 51
d. Three answers above are wrong.
11. Invoke f2(15):
a. Print 3
b. Print 15
c. Print nothing
d. Three answers above are wrong.
12. Invoke f1(f2(39))
a. Print 3 35
b. Print 35
c. Print 335
d. Three answers above are wrong.
13. Invoke f2(f1(39)
a. Print 287
b. Print 35
c. Print 2870
d. Three answers above are wrong.
14. Invoke f2(f2(39))
a. Print 133
b. Print 13 3
c. Print 313
d. Three answers above are wrong.
15. Which one is correct statement?
a. a=b+f1(a);
b. a=b+f2(a);
c. a=f1(f2(b));
d. a=f2(f1(b));
Given a short code:
int a=5, b=6, y;
y=a&&(a>b++)&&–b;
16. Value of b, y are:
a. b=5, y=0
b. b=6, y=1
c. b=7, y=0
d. Three answers above are wrong.
17. Given a short code:
int x=11, y=5, b;
b=(x-y)?(x&&y):(x||y);
Value of b:
a. 14
b. 15
c. 1
d. 0
18. Given a short code:
int a=10, b=7; float y;
y=(b+1)*(a/b);
printf(“%5.2f”,y);
Result:
a. 11.43
b. 11.42
c. 8
d. 8.00
19. Given a variable declaration:
int a,b, *p1, *p2;
Which one is wrong statement?
a. p1=a;
b. p2=&b+1;
c. p1=p2+a;
d. p1=&a+1;
20. Given a variable declaration:
int *p1, *p2, *p3;
Which one is correct statement?
a. p3=p1+p2;
b. p3=p2-p1;
c. *p3=p1-p2;
d. p3=2*p1;
21. Given a short code:
int x=1,i;
for(i=1; i<10; i++)
{
x+=++i;
if(i==5)
break;
}
printf(“%d”,x);
Result:
a. 31
b. 7
c. 55
d. Three answers above are wrong.
22. Given a short code:
int i=1, j=2; float S=0;
do {
S+=i/j;
i++;
j*=2;
} while(i<15);
printf(“%3.2f”, S);
Result:
a. 2.0
b. 2.00
c. 0.00
d. 0.0
23. Given a short code:
int a=1, b=0;
while(a<=b&&++b)
if(a==b)
break;
printf(“%d %d”, a,b);
Result:
a. 1 0
b. 1 1
c. 11
d. Three answers above are wrong.
24. Given a short code:
#include<stdio.h>
int a,b;
main()
{
switch(a-b?5:b++)
{
default: a=b+=2;
case 5: b+=5;
case 1: a–;
}
}
Result:
a. a=2, b=8
b. a= -1, b=1
c. a= -1, b=6
d. Three answers above are wrong.
25. Given a short code:
#include<stdio.h>
int a=1,b=2;
main()
{
switch(a=3)
{
case 3: a+=2;
default: b++;
break;
case 0: a–;
}
}
Result:
a. a=1, b=3
b. a=5, b=3
c. a=4, b=3
d. Three answers above are wrong.
26. Given a short code:
#include<stdio.h>
int change(int *a);
main()
{
int x=3, y=0;
while(x>change(&y)) ;
printf(“%d”,y);
}
int change(int *a)
{
static int temp=1;
*a+=temp++;
return temp;
}
Result:
a. Print 0
b. Wrong syntax
c. Print 1
d. Print 3
Given a short code(is used for 27, 28, 29,30)
#include<stdio.h>
void func1(int *a, int b);
void func2(int *a, int *b);
main()
{
int a=15, b=8;
func1(&b,a);
printf(“%d %d”, a,b);
func2(&a,&a);
printf(“%d %d”,a,b);
}
void func1(int *a, int b)
{
*a+=b++;
func2(&b,a);
printf(“%d %d”, *a, b);
return;
}
void func2(int *a, int *b)
{
if(*a>*b)
*a+=*b;
else *a-=2;
printf(“%d %d”, *a, *b);
return;
}
27. The function func2 outputs:
a. 14 23
b. 13 13
c. Both a,b are correct.
d. Both a, b are wrong.
28. The function func1 outputs:
a. 23 14
b. 14 23
c. 23 23
d. Both a,b are correct.
29. The output of printf in main function BEFORE invoking func2:
a. 15 8
b. 15 23
c. 13 8
d. Three answers above are wrong.
30. The output of printf in main function AFTER invoking func2:
a. 15 8
b. 13 23
c. 13 8
d. Three answers above are wrong.
Answer: 1.C 2.C 3.B 4.A 5.B 6.C 7.A 8.A 9.D 10.B 11.A 12.D 13.D 14.C 15.B 16.C 17.C 18.D 19.A 20.C 21.A 22.C 23.A 24.A 25.B 26.D 27.C 28.D 29.B 30.B