MCQs
Because, case 3 + 2: and case 5: have the same constant value 5.
The while() loop must have conditional expression or it shows "Expression syntax" error.
Example: while(i > 10){ ... }
There can exists a switch statement, which has no case.
Step 1: for(;;) this statement will genereate infinite loop.
Step 2: printf("%d`setminus`n", i++); this statement will print the value of variable i and
increement i by 1(one).
Step 3: if(i>10) here, if the variable i value is greater than 10, then the for loop breaks.
Hence the output of the program is
1
2
3
4
5
6
7
8
9
10
Step 1: x=y=z=1; here the variables x ,y, z are initialized to value '1'.
Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here ++x
becomes 2. So there is no need to check the other side because ||(Logical OR) condition is
satisfied.(z = (2 || ++y && ++z)). There is no need to process ++y && ++z. Hence it returns
'1'. So the value of variable z is '1'
Step 3: printf("x=%d, y=%d, z=%d`setminus`n", x, y, z); It prints "x=2, y=1, z=1". here x is increemented
in previous step. y and z are not increemented.
switch(i) has the variable i it has the value '1'(one).
Then case 1: statements got executed. so, it prints "Hi". The break; statement make the
program to be exited from switch-case statement.
switch-case do not execute any statements outside these blocks case and default
Hence the output is "Hi".
Answer: Option(A)
In the very begining of switch-case statement default statement is encountered.
So, it prints "This is default".
In default statement there is no break; statement is included. So it prints the case
1 statements. "This is case 1".
Then the break; statement is encountered. Hence the program exits from the switch-case block.
The logical not operator takes expression and evaluates to true if the expression is false and
evaluates to false if the expression is true. In other words it reverses the value of the expression.
Step 1: if(!(!x) && x)
Step 2: if(!(!10) && 10)
Step 3: if(!(0) && 10)
Step 3: if(1 && 10)
Step 4: if(TRUE) here the if condition is satisfied. Hence it prints x = 10.
Answer: Option A
The keyword continue cannot be used in switch case. It must be used in for or while or do
while loop. If there is any looping statement in switch case then we can use continue.