Sail E0 Webinar

MCQs

Total Questions : 30 | Page 2 of 3 pages
Question 11.

Which of the following sentences are correct about a for loop in a C program?

1: for loop works faster than a while loop.

2: All things that can be done using a for loop can also be done using a while loop.

3: for(;;); implements an infinite loop.

4:for loop can be used if we want statements in a loop get executed at least once.


  1.    1
  2.    1, 2
  3.    2, 3
  4.    2, 3, 4
 Discuss Question
Answer: Option D. -> 2, 3, 4


Question 12.


Which of the following statements are correct about the program?


#include<stdio.h>
int main()
{
int x = 30, y = 40;
if(x== y)
printf("x is equal to y\n");
else if (x > y)
printf("x is greater than y\n");
else if (x > y)
printf("x is less than y\n")
return 0;
}
  1.    Error: Statement missing
  2.    Error: Expression syntax
  3.    Error: Lvalue required
  4.    Error: Rvalue required
 Discuss Question
Answer: Option A. -> Error: Statement missing

This program will result in error "Statement missing ;"

printf("x is less than y`setminus`n") here ; should be added to the end of this statement.



Question 13.


Which of the following statements are correct about the below C-program?


#include<stdio.h>
int main()
{
int x = 10, y = 100%90, i,
for(i = 1; i
  1.    1
  2.    2, 3
  3.    3, 4
  4.    4
 Discuss Question
Answer: Option B. -> 2, 3


Question 14.

Which of the following statements are correct about the below program?


#include<stdio.h>
int main()
{
int i = 0;
i++;
if(i
  1.    The program prints 'Placementadda' 5 times
  2.    The program prints 'Placementadda' one time
  3.    The call to main() after exit() doesn't materialize.
  4.    The compiler reports an error since main() cannot call itself
 Discuss Question
Answer: Option B. -> The program prints 'Placementadda' one time

Step 1: int i = 0; here variable i is declared as an integer type and initialized to '0'(zero).
Step 2: i++; here variable i is increemented by 1(one). Hence, i = 1
Step 3: if(i <= 5) becomes if(1 <= 5) here we are checking '1' is less than or equal to '5'.

 Hence the if condition is satisfied.
Step 4: printf("Placementadda`setminus`n"); It prints "Placementadda"
Step 5: exit(); terminates the program execution.

Hence the output is "Placementadda".



Question 15.

Which of the following statements are correct about an if-else statements in a C-program?

1:  Every if-else statement can be replaced by an equivalent statements using  ?: operators

2:  Nested if-else statements are allowed.

3:  Multiple statements in an if block are allowed.

4:  Multiple statements in an else block are allowed.


  1.    1 and 2
  2.    2 and 3
  3.    1, 2 and 4
  4.    2, 3, 4
 Discuss Question
Answer: Option D. -> 2, 3, 4

No answer description available for this question. 


Question 16.


Which of the following statements are correct about the below program?


#include<stdio.h>
int main()
{
int i = 10, j = 15;
if(i % 2 = j %3)
printf("Placementadda\n");
return 0;
}
  1.    Error: Expression syntax
  2.    Error: Lvalue required
  3.    Error: Rvalue required
  4.    The Code runs successfully
 Discuss Question
Answer: Option B. -> Error: Lvalue required

if(i % 2 = j % 3) This statement generates "LValue required error". 

There is no variable on the left side of the expression to assign (j % 3).


Question 17.

Point out the error, if any in the program.


#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf("Case1");
break;
case 1*2+4:
printf("Case2");
break;
}
return 0;
}
  1.    Error: in case 1*2+4 statement
  2.    Error: No default specified
  3.    Error: in switch statement
  4.    No Error
 Discuss Question
Answer: Option D. -> No Error

Constant expression are accepted in switch

It prints "Case1"


Question 18.


Point out the error, if any in the program.


#include<stdio.h>
int main()
{
int a = 10, b;
a >=5 ? b=100: b=200;
printf("%d\n", b);
return 0;
}
  1.    100
  2.    200
  3.    Error: L value required for b
  4.    Garbage value
 Discuss Question
Answer: Option C. -> Error: L value required for b

Variable b is not assigned.

It should be like: 
b = a >= 5 ? 100 : 200;


Question 19.


Which of the following statements are correct about the below program?


#include<stdio.h>
int main()
{
int i = 10, j = 20;
if(i = 5) && if(j = 10)
printf("Have a nice day");
retrurn 0;
}
  1.    Output: Have a nice day
  2.    No output
  3.    Error: Expression syntax
  4.    Error: Undeclared identifier if
 Discuss Question
Answer: Option C. -> Error: Expression syntax

"Expression syntax" error occur in this line if(i = 5) && if(j = 10).

It should be like if((i == 5) && (j == 10)).


Question 20.


Point out the error, if any in the 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;
}
  1.    Error: No default value is specified
  2.    Error: Constant expression required at line case P:
  3.    Error: There is no break statement in each case.
  4.    No error will be reported
 Discuss Question
Answer: Option B. -> Error: Constant expression required at line case P:

The compiler will report the error "Constant expression required" in the line 

case P: . Because, variable names cannot be used with case statements.

The case statements will accept only constant expression.


Latest Videos

Latest Test Papers