Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 08
1-
What will be the output of the program?
#include<stdio.h>
int main()
{
int x = 10, y = 20;
if(!(!x) && x)
printf("x = %d\n", x);
else
printf("y = %d\n", y);
return 0;
}
A -
y =20
B -
x = 0
C -
x = 10
D -
x = 1
2-
What will be the output of the program?
#include<stdio.h>
int main()
{
int i=4;
switch(i)
{
default:
printf("This is default\n");
case 1:
printf("This is case 1\n");
break;
case 2:
printf("This is case 2\n");
break;
case 3:
printf("This is case 3\n");
}
return 0;
}
A -
This is default This is case 1
B -
This is case 3 This is default
C -
This is case 1 This is case 3
D -
This is default
3-
What will be the output of the program?
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf("Hello\n");
case 1:
printf("Hi\n");
break;
case 2:
printf("\nBye\n");
break;
}
return 0;
}
#include<stdio.h>
int main()
{
int x, y, z;
x=y=z=1;
z = ++x || ++y && ++z;
printf("x=%d, y=%d, z=%d\n", x, y, z);
return 0;
}
A -
x=2, y=1, z=1
B -
x=2, y=2, z=1
C -
x=2, y=2, z=2
D -
x=1, y=2, z=1
6-
Point out the error, if any in the for loop.
#include<stdio.h>
int main()
{
int i=1;
for(;;)
{
printf("%d\n", i++);
if(i>10)
break;
}
return 0;
}
A -
There should be a condition in the for loop
B -
The two semicolons should be dropped
C -
The for loop should be replaced with while loop.
D -
No error
7-
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int a = 10;
switch(a)
{
}
printf("This is c program.");
return 0;
}
A -
Error: No case statement specified
B -
Error: No default specified
C -
No Error
D -
Error: infinite loop occurs
8-
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf("This is c program.");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
A -
Error: No default specified
B -
Error: Invalid printf statement after switch statement
C -
No Error and prints "Case1"
D -
None of above
9-
Point out the error, if any in the while loop.
#include<stdio.h>
int main()
{
int i=1;
while()
{
printf("%d\n", i++);
if(i>10)
break;
}
return 0;
}
A -
There should be a condition in the while loop
B -
There should be at least a semicolon in the while
C -
The while loop should be replaced with for loop.
D -
No error
10-
Which of the following errors would be reported by the compiler on compiling the program given below?
#include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf("First");
case 2:
printf("Second");
case 3 + 2:
printf("Third");
case 5:
printf("Final");
break;
}
return 0;
}