This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1Which of the following is unconditional control jumping statement?
Option D
An unconditional control jumping statement transfers the flow of execution directly from one part of the program to another without checking any condition.
The goto statement transfers program control from one part to another without testing any condition. The goto transfers control unconditionally.
Q: 2What will be the output of the following code?
int a=5;
int b=10;
if(a<3 || b>15)
printf("True");
else
printf("False");
Option B
The condition inside the if statement is (a<3 || b>15), which uses the logical OR (||) operator. First, a<3 is evaluated, since 5<3 is false, this part returns 0. Next, b>15 is evaluated, since 10>15 is also false, this part also returns 0.
The logical OR operation 0 || 0 results in 0, meaning the condition is false. Therefore, the else block is executed, and the output printed on the screen is "False".
Q: 3Which of the following C statements is valid?
Option D
In C, the condition inside an if statement must be a valid expression that evaluates to true (non-zero) or false (0).
The statement if(2>3?0:1) {}; uses the ternary operator (?:), which is a valid expression.
| Statement | Why Wrong? |
|---|---|
| if(return(1)) {}; | The return is a control statement and cannot be used inside a condition expression. |
| if(switch(1)) {}; | The switch is a statement, not an expression, so it cannot be used inside if. |
| if (if(1)) {}; | Nested if inside condition is invalid syntax in C. |
Q: 4What will be printed for the following C program?
#include<stdio.h>
int main()
{
int a=100,b=30;
if(a<25) { a=a-50; }
else { b=b+50; }
printf(“a=%d, b=%d”,a,b);
return 0;
}
Option A
Initially, a=100 and b=30. The condition a<25 is checked, but since 100 is not less than 25, the condition is false and the else block executes. Inside the else block, b is increased by 50, so b becomes 80. The value of a remains unchanged. Therefore, the output printed is a=100, b=80.
Q: 5Which of the following statement is true regarding goto statement in C Language?
Option D
In C language, the goto statement is used to jump from one part of a program to another within the same function. It transfers control directly to a labeled statement.
Syntax:
goto label;
.....................
label:
Here, execution jumps to label: when goto is executed.
Q: 6No two-case statement have _________ in the same switch.
Option A
In a switch statement, no two case labels can have identical values, each case value must be unique.
If two case labels have the same value, the compiler cannot decide which block to execute, so it is not allowed.
Q: 7Find output of the code given below
#include<stdio.h>
int main(void)
{
int i;
for(int i=0;i<3;i++)
{
switch(i)
{
case 0: printf("a");
case 1: printf("b");
default: printf("c"); break;
}
}
}
Option A
In a switch statement, if a case does not have a break, execution continues to the next cases until a break is encountered.
The loop runs for i=0,1,2.
After combining all outputs from each iteration of the loop, we get "abc" for i=0, "bc" for i=1, and "c" for i=2. When these are concatenated in order, the final output becomes abcbcc.
Q: 8What is the output of the below program?
#include<stdio.h>
void main()
{
int i=0;
switch (i)
{
case '0':
printf("Suraku");
break;
case '1':
printf("Academy");
break;
default:
printf("Suraku Academy");
}
}
Option B
In C, a switch statement compares the value of the switch expression with the values in each case.
Here, the variable i is an integer with value 0. The case labels '0' and '1' are character constants, not integers 0 and 1.
In C, '0' has an ASCII value of 48 and '1' has an ASCII value of 49. Since i (0) does not match either 48 or 49, none of the case statements are executed. As a result, the default case runs and prints "Suraku Academy".
Q: 9The switch case statement can only test
Option A
The switch statement checks whether the value of the expression is equal to one of the case constants. If a match is found, the corresponding case block is executed. So, switch-case performs only equality checking.
Q: 10To transfer program control from one part to another part without testing any condition using?
Option D
In C language, program control usually changes based on conditions. Statements like if, if-else, and switch all check a condition or expression before transferring control.
The goto statement transfers program control from one part to another without testing any condition. The goto transfers control unconditionally.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.