C MCQ by Sampat Liler
C MCQ by Sampat Liler
Answer – C
Answer – C
3. Choose a right statement.
int a = 3.5 + 4.5;
A) a = 0
B) a = 7
C) a = 8
D) a = 8.0
Answer – B
4.Choose right statement.
int main()
{
float c = 3.5 + 4.5;
printf("%f", c);
return 0;
}
A) 8.0
B) 8.000000
C) 8
D) 7
Answer – B
5. Choose a right statement.
int main()
{
float c = 3.5 + 4.5;
printf("%d", (int)c);
return 0;
}
A) 8.0
B) 8.000000
C) 7
D) 8
Answer – D
6. Choose a right statement.
int a = 5/2;
int b = 5.0/2;
int c = 5 / 2.0;
int d = 5.0/2.0;
A) a = 2, b = 2, c = 2, d= 2
B) a = 2, b = 2.0, c = 2, d= 2.0
C) a = 2, b = 2.5, c = 2.5, d= 2.5
D) a = 2.5, b = 2.5, c = 2.5, d= 2.5
Answer - A
7. What is the output of the program.?
int main()
{
int a = 25%10;
printf("%d", a);
return 0;
}
A) 2.5
B) 2
C) 5
D) Compiler error.
Answer – C
8. Which data type cannot be checked in switch-
case statement?
A.enum
B.character
C. integer
D.float
Answer – D
9. How many times "Anvira Education" is printed?
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("Anvira Education");
}
return 0;
}
A.10 times
B.11 times
C. 0 times
D.Infinite times
Answer – C
10. How many times while loop is executed if a short
int is 2 byte wide?
#include<stdio.h>
int main()
{
int i=1;
while(i <= 155)
{
printf("%c %d\n", i, i);
i++;
}
return 0;
}
A.154 times
B.155 times
C. 156 times
D.Infinite times
Answer – B
11. Which statement is correct about the below
program?
#include<stdio.h>
int main()
{
int i = 8, j = 24;
if(i = 8) && if(j = 24)
printf("Welcome Programmer");
return 0;
}
A.Welcome Programmer
B.Error: Undeclared identifier if
C. Error: Expression syntax
D.No output
Answer – B
12. Find out the error, if any in the below program?
#include<stdio.h>
int main()
{
int j = 1;
switch(j)
{
printf("Hello programmer!");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
A.No error in program and prints "Case1"
B.Error: Invalid printf statement after switch
statement
C. Error: No default specified
D.None of the above
Answer – A
Answer – D
14. Which statements are correct about an if-else
statement in a C-program?
1. Nested if-else statements are allowed
2. Every if-else statement can be replaced by an
equivalent statement using ?: operators
3. Multiple statement in else block are allowed
4. Multiple statement in if block are allowed
A.1, 3 and 4
B.1, 2, 3 and 4
C. 2 , 3and 4
D.1 and 4
Answer – A
15. Find out the error, if any in the below program?
#include<stdio.h>
int main()
{
int P = 10;
switch(P)
{
case 10:
printf("Case 1");
case 20:
printf("Case 2");
break;
case P:
printf("Case 2");
break;
}
return 0;
}
A.Error: Constant expression required at line case
P:
B.Error: There is no break statement in each case
C. Error: No default value is specified
D.No error
Answer – A
Answer – D
Answer – B
19. What is the output of the given program?
#include<stdio.h>
int main()
{
int a=5;
do
{
printf("%d\n",a);
a= -1;
}while (a>0);
return 0;
}
A.-1
B.5
C. 0
D.Compile error
Answer – B
20. What is the built-in library function for
comparing the two strings?
A.strcmp()
B.equals()
C. str_compare()
D.string_cmp()
Answer – A
Answer – C
23. What will be the output of the below program?
#include<stdio.h>
main(){
int x[] = {100, 200, 300};
printf("%d", *x +1);
}
A.100
B.200
C. 101
D.201
Answer – C
24. What will be the output of the below program?
#include<stdio.h>
void main()
{
char a[] = "C++";
printf("%s ",a);
a++;
printf("%s",a);
}
A.C++ ++
B.++ ++
C. C++ C++
D.Compile error
Answer – D
25. In a structure, if a variable works as a pointer
then from the given below operators which
operator is used for accessing data of the
structure using the variable pointer?
A.%
B.->
C. .
D.#
Answer – B