Saturday, October 25, 2008

1&2 years Programming and Debugging Paper _October08

1.
void main()
{
int d=5;
printf("%f",d);
}
1)5 2)5.000000 3)no output 4)error
Ans: 3

2.
void main()
{
int i;
for(i=1;i<4;i++)
switch(i)
{
case 1: printf("%d",i);break;
{
case 2:printf("%d",i);break;
case 3:printf("%d",i);break;
}
}
switch(i) case 4:printf("%d",i);
}
1)1 4 2)1 2 3 4 3)1 4 4 4 4)none
Ans: 2

3.
void main()
{
float j;
j=1000*1000;
printf("%f",j);
}
1)100000 2)16960.000000 3)100000.000000 4)error
Ans: 2

4.
void func()
{
int x = 0;
static int y = 0;
y++;
printf( "%d -- %d\n", x, y );
}
int main()
{
func();
func();
return 0;
}
1)0 - -0,0 - - 0 2)error 3)0 - -1.,0 - -2 4)0 - -1,0 - -1
Ans : 3


5.
void main()
{
int a,b=5,c=10;
a = (b-c) > (c-b) ? b : c;
printf(“%d”,a);
}
1)10 2)5 3)-5 4)-10
Ans:1

6.
main()
{int i=4;
fun(i=i/4);
printf("%d", i);
}
fun(int i)
{return i/2;
}
1)1 2)0 3)no output 4)error
Ans: 4

7.
main()
{char str[]="Geneius";
printf("%s",str);
}
print(char *s)
{if(*s)
print(++s);
printf("%c",*s);
}
1)Geneius 2)eneius 3)error 4)garbage value
Ans: 1

8.
main()
{
static int a[]={5,10,15,20};
int * ptr=a;
int ** ptr_ptr=&ptr;
printf("\n %d",**ptr_ptr++);
}
1)5,10 2)10,15 3)error 4)5
Ans: 4

9.
void main()
{
char buffer[10]={"Genesis"};
printf("%d",&buffer[4]-(buffer));
}
a) 3
b) 4
c.)0
d) illegal pointer subtraction
Ans: 4

10.
main()
{
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];
printf("%d", b[-1]);
}
1)error 2)3 3)garbage value 4)6
Ans: 4

11.
#include
char*g()
{
static char x[1024];
return x;
}
main()
{
char*g1="First String";
strcpy(g(),g1);
g1=g();
strcpy(g1,"Second String");
printf("Answer is:%s", g());
}
A) Answer is: First String (B) Answer is: Second String
(C) Run time Error/Core Dump (D) None of these
Ans: 2


12.
func(int i)
{
if(i%2) return 0;
else return 1;
}
main()
{
int i=3;
i=func(i);
i=func(i);
printf("%d",i);
}
(A) 3 (B) 1 (C) 0 (D) 2
Ans:1

13.
main()
{ int a=500,b,c;
if(a>400)
b=300;
c=2--;
printf("\n%d%d",b,c);
}
1)300,1 2)0,0 3)300,2 4)error
Ans: 4

14.
void main(void)
{
int i=100,j=20;
i++=j;
i*=j;
printf("%d\t%d\n",i,j);
}
1)21,420 2)100,20 3)error 4)21,20
Ans:3

15.
main()
{
const int x=5;
int *ptrx;
ptrx=&x;
*ptrx=10;
printf("%d",x);
}
a) 5 b) 10 c) Error d) Garbage value
Ans: 3


16.
main()
{
int n=5;
printf("\nn=%*d",n,n);
}
a) n=5 b) n=5,5 c) n= 5 d) error
Ans: 3

17.
void main()
{
int a=5,b=10;
int &ref1=a,&ref2=b;
ref1=ref2;
++ ref1;
++ ref2;
printf("%d %d",a,b);
}
a)5 and 12
b)Error
c)11 and 11
d)5 10
Ans:3

18.
void main()
{
enum bool{true,false};
if(true==(2==3))
printf("hai");
else
printf("Hello");
}
1)hai 2)Hello 3)no output 4)haiHello
Ans: 1

19.
void main()
{
printf("%d",(float)3/2);
}
1)1.50000 2)0 3)1.5 4)1
Ans: 2



20.
main()
{
char *a="hello";
char *b="bye";
char *c="hai";
int x=10,y=100;
c=(xprintf("%s",c);
}
1)hai 2)bye 3)hello 4)no ouput
Ans: 3


21.
# define MAX(a, b) a>b ? a:b
main()
{
int m, n;
m = 3 + MAX(2, 3);
n = 2 * MAX(3, 2);
printf("m = %d, n = %d\n", m, n)
}
1)m=2,n=3 2)m=3,n=2 3)m=3,n=3 4)m=2,n=2
Ans : 1

22.
main()
{
int n=0;
int i;
i=2;
switch(1)
{
case 0:do{
case 1:n++;
case 2:n++;
}
while(--i>0);
}
printf("\nn==%d",n);
}
1)2 2)3 3)4 4)none
Ans: 3



23.
void main()
{
printf("%d",printf("ABC\\"));
}
(a) ABC\\
(b) 1
(c) ABC\4
(d) ABC\3
Ans:3

24.
int compute(int n)
{
if(n>0)
{
n=compute(n-3)+compute(n-1);
return(n);
}
return(1);
}

void main()
{
printf("%d",compute(5));
}
(a) 6
(b) 9
(c) 12
(d) 13
Ans: 2

25.
void main()
{
int i;
for(i=0;i<3;i++)
{
int i=100;
i--;
printf("%d..",i);
}
}

(a0..1..2..
(b)99..98..97..
(c)100..100..100..
(d)99..99..99..
Ans: 4

26.
void main()
{
int a[]={10,20,30,40,50};
int *p;
p= (int*)((char *)a + sizeof(int));
printf("%d",*p);
}
(a)10
(b)20
(c)30
(d)40
Ans: 2

No comments: