MCQs
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.
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.
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".
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.
No answer description available for this question.
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).
Constant expression are accepted in switch
It prints "Case1"
Variable b is not assigned.
It should be like:
b = a >= 5 ? 100 : 200;
"Expression syntax" error occur in this line if(i = 5) && if(j = 10).
It should be like if((i == 5) && (j == 10)).
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.