1. The output of the following code is:
void main()
{
int z, a = 5, b = 3; z = a * 2 + 26 % 3;
printf("%d", z); }
(a) 10
(b) 0
(c) 12
(d) None of the above
Answer: (c) 12
2. Which options shows the correct hierarchy of arithmetic operators
(a) **, * or /, + or -
(b) **, *, /, +, -
(c) **< /< *< +<-
(d) / or *, - or +
Answer: (d) / or *, - or +
3. The output of the following code is:
void main()
{
float a;
int x = 10, y = 3; a = x / y;
printf("%f", a); }
(a) 3.999999
(b) Error
(c) 3
(d) 3.000000
Answer: (d) 3.000000
4. The output of the following code is:
void main()
{
char a = 'B';
switch (a)
{
case 'A' : printf("a");
case 'B' : printf("b");
default : printf("c");
}
(a) B
(b) b
(c) bca
(d) bc
Answer: (d) bc
5. The output of the following code is:
void main()
{
int a = 20;
printf("%d\t%d
", ++a, a);
}
(a) 21 21
(b) 20 21
(c) 21 20
(d) 20 20
Answer: (c) 21 20
6. How many times the following loop will execute?
for (a = 0; a < 4; a++)
printf("hello
");
(a) 3
(b) 4
(c) 5
(d) infinite
Answer: (b) 4
7. The output of the following code is:
void main()
{
int a;
int &b = a;
a=100;
printf("b=%d\ta=%d
", b,a);
}
(a) b=100 a=100
(b) b=100 a=0
(c) b=0 a=100
(d) Error
Answer: (d) Error
8. The output of the following code is:
void main()
{
int a = 0;
while (a<=50) for(;;) if(++a % 50==0) break;
printf("a = %d", a);
}
(a) a = 100
(b) a = 50
(c) compilation error
(d) runtime error
Answer: (a) a = 100
9. The output of the following code is:
int f(int a, int b);
void main()
{
int a = 12, b=154;
printf("%d", f(a, b));
}
int f(int a, int b)
{
if (a<b) return(f(b, a));
if(b==0) return(a);
return (f(b, a % b));
}
(a) 2
(b) 1
(c) Compilation error
(d) Runtime error
Answer: (a) 2
10. The output of the following code is:
void main()
{
int a = 1, b=2;
int *ip;
ip=&a;
b=*ip;
printf("%d", b);
}
(a) 2
(b) 1
(c) 100
(d) 0
Answer: (b) 1
No comments:
Post a Comment