Recently I have prepared a Multiple Choice Question Paper for a Coding and Debugging contest. I thought it might be a good idea to post those questions here. Most of the questions and their solutions are already discussed in this blog.
1. #include<stdio.h>
int main( )
{
int x;
int *y;
int **z;
x=10;
y=&x;
z=&y;
printf(“%d”,*z);
return 0;
}
A. Syntax Error B.
10 C. Address of
y D. Address
of x
2. #include<stdio.h>
int main( )
{
enum tag {a, b=3, c};
printf(“%d%d”,a,c);
return 0;
}
A.
Syntax Error B. 14 C. 13 D. 04
3. #include<stdio.h>
int main( )
{
int a[ ] = {1,2,3};
int i=2;
printf(“%d”,i[a]);
return 0;
}
A.
Address of i B. 2 C. 3 D. Syntax Error
4. #include<stdio.h>
int main( )
{
int a,b;
float c;
a=10;
b=5;
c=(a+b)/2;
printf(“%f”,c);
return 0;
}
A.
7.000000 B. 7.500000 C. 7 D. Syntax Error
5. #include<stdio.h>
int main()
{
int a;
int *b;
a=10;
b=&a;
printf(“%d”,b);
return 0;
}
A.
10 B. Address of a C. Syntax Error D. Address of b
6. #include<stdio.h>
int main( )
{
float a;
a = 10.5;
printf(“%d”,a);
return 0;
}
A. 10.500000 B. 10.000000 C. 0
D. 10
7. #include<stdio.h>
int main( )
{
int ch=1;
switch (ch)
{
case 1: printf(“1”);
case 2: printf(“2”);
case 3: printf(“3”);
}
}
A. 123 B. Syntax
Error C. 2 D. 1
8. #include<stdio.h>
int main()
{
int x,y,z;
x=5;
y=10;
z=x+++++y;
printf(“%d”,z);
return 0;
}
A. 10 B. Syntax Error C. 15 D. 5
9. #include<stdio.h>
#define SQR (x) x * x
int main( )
{
int a;
a = SQR (3+5);
printf(“%d”,a);
return 0;
}
A. 64
B. 25 C. 23 D. Syntax Error
10. #include<stdio.h>
int main()
{
int x,y,z;
x=10;
y=20;
z=x+++y;
printf(“%d”,z);
return 0;
}
A. 30 B. 31 C. 32 D. Syntax Error
11. #include<stdio.h>
int main( )
{
int x;
int *ptr;
x=10;
ptr=&x;
(*ptr)++;
printf(“%d”,x);
return 0;
}
A. 10 B. 11 C. 12 D. Syntax Error
12. #include<stdio.h>
int main( )
{
const char str [ ] = “hello”;
str[0] = ‘H’;
printf(“%s”,str);
return 0;
}
A. Syntax Error B. Hello C. hello D. ello
13.
#include<stdio.h>
int a;
int main( )
{
printf(“%d”,a);
return 0;
}
A. Compile Time Error B. Run Time Error C. 0 D. Garbage Value
14. #include<stdio.h>
int main( )
{
int i=-1;
if(i< sizeof(int))
{
printf(“%d”,-i);
}
else
{
printf(“%d”,+i);
}
return 0;
}
A. 1 B. Syntax Error C. -1 D. 11
15. #include<stdio.h>
int main( )
{
int a=10,b;
b=sizeof(++a);
printf(“%d%d”,a,b);
return 0;
}
A. 104 B. 114 C. 102 D. Syntax
Error
No comments:
Post a Comment