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: 1Why is type conversion needed?
Option D
Type Conversion is needed to convert a value from one data type to another so that it can be properly stored or used in a variable of a different type.
Q: 2Which of the following operators takes only integer operand?
Option D
The operators + (addition), * (multiplication), and / (division) can work with both integer and floating-point operands. There is no restriction that these operators must take only integer operands.
Q: 3Conditional operator also known as
Option C
The conditional operator is also called the ternary operator because it works with three operands.
Syntax:
(condition) ? True Part : False Part;
#include <stdio.h>
int main()
{
int a,p,q,min;
printf("Enter A Number : ");
scanf("%d",&a);
a%2==0?printf("%d is Even",a):printf("%d is Odd",a);
printf("
Enter Two Number : ");
scanf("%d%d",&p,&q);
min=p<q?p:q;
printf("Minimum : %d",min);
return 0;
}
OUTPUT
Enter A Number : 89
89 is Odd
Enter Two Number : 63 58
Minimum : 58
Q: 4The two operator && and || are
Option A
The operators && (AND) and || (OR) are called logical operators. They are used to combine multiple conditions in decision-making statements like if, while, or for.
#include <stdio.h>
int main()
{
int a, b;
printf("Enter two Numbers: ");
scanf("%d%d",&a,&b);
if (a>0 && b>0)
{
printf("Both Numbers are Positive.
");
}
if (a<0 || b<0)
{
printf("At least One Number is Negative.
");
}
if (!(a == b))
{
printf("The Numbers are Not Equal.");
}
return 0;
}
OUTPUT
Enter two Numbers: -87 56
At least One Number is Negative.
The Numbers are Not Equal.
Q: 5Which operator from the following has the lowest priority?
Option A
The higher order precedence of given operators is:
Q: 6What are the values of ‘a’, ‘b’ and ‘c’ after the execution of the following statements in a C program?
int a,b,c;
b=10;
c=15;
a=++b + c++;
Option B
After b=10; and c=15;, the statement a = ++b + c++; evaluates as follows in C:
Thus, a=11+15 = 26, with final values a=26, b=11, c=16.
Q: 7What is result of -17%5?
Option B
The modulus operator (%) is used to find the remainder after division of two integers. The sign of the result of % depends on the sign of the left operand (dividend). So, so -17%5 results in -2.
Note:
For solving % operator, there is no direct approach so it can be solved by using the equation, a%b=a-(a/b)*b and sign of remainder is determined by sign of first operand left to % symbol (dividend).
Now, the given expression is −17%5. Here a is -17 and b is 5.
a%b=a-(a/b)*b
-17%5 = -17-(-17/5)*5
-17%5 = -17-(-3*5)
-17%5 = -17+15
-17%5 = -2
Q: 8What is output of below code
void main()
{
int a=5, b=17, c=8, d;
d=(a=c,b+=a,c=a+b+c);
printf("%d %d %d %d", d, a, b, c);
}
Option B
The comma operator evaluates expressions from left to right, and the value of the entire expression is the value of the last expression.
| Expression Evaluated | Explanation | a | b | c | d |
|---|---|---|---|---|---|
| — | Initial values. | 5 | 17 | 8 | — |
| a = c | Assign value of c i.e., 8 to a. | 8 | 17 | 8 | — |
| b += a | b = b + a. so, 17 + 8 = 25 | 8 | 25 | 8 | — |
| c = a + b + c | c = 8 + 25 + 8 = 41 | 8 | 25 | 41 | — |
| d = (Last Value) | d gets value of last expression i.e., 41 | 8 | 25 | 41 | 41 |
Q: 9What is the symbol and associativity of the assignment operator?
Option D
The assignment operator is represented by the symbol =. It is used to assign a value to a variable.
The associativity of the assignment operator is Right to Left. This means that when multiple assignment operators appear in the same expression, evaluation starts from the right side.
E.g.:
int a,b,c;
a=b=c=5;
This statement is evaluated as a=(b=(c=5));
Q: 10The result of statement printf("%d",(17*2)%(int)5.5); is?
Option B
In the given statement printf("%d",(17*2)%(int)5.5); first, 17*2 gives 34. Then type casting is applied, where (int)5.5 converts the floating-point value 5.5 into the integer value 5 by removing the decimal part.
After this, the expression becomes 34%5. The modulus operator returns the remainder after division, and when 34 is divided by 5, the remainder is 4. Therefore, the value printed by printf() is 4.
Q: 11In the following C program snippet, what is the output that gets printed.
#include<stdio.h>
main()
{
int x=2,y,z;
x*=3+2;
x*=y=z=4;
printf(“%d”,x);
}
Option B
In C, operators follow precedence and associativity rules. Also, assignment operations are evaluated from Right to Left.
Initially, the value of x is 2. In the first statement x*=3+2, the addition is performed first, so 3+2 = 5, and then x is multiplied by 5, making x = 2*5 = 10.
In the next statement x*=y=z=4, assignment operators are evaluated from right to left. So first z is assigned 4, then y is assigned 4. After that, the expression becomes x *= 4, so x = 10*4 = 40.
Finally, the printf statement prints the value of x, which is 40.
Q: 12What will be value of i and k after execution the following code.
void main()
{
int i,j,k;
j=5;
i=2;
i=2*j/2;
k=2*(j/i);
}
Option D
| EXPRESSION | CALCULATION | RESULT |
|---|---|---|
| j = 5 | — | j = 5 |
| i = 2 | — | i = 2 |
| i = 2 * j / 2 | 2 * 5 / 2 | 10 / 2 = 5 |
| k = 2 * (j / i) | 2 * (5 / 5) | 2 * 1 = 2 |
Q: 13The result of the statement printf("%d",(10/3)*3+!5%3); is?
Option C
| Expression | Explanation | Result |
|---|---|---|
| 10/3 | Integer division, decimal part discarded. | 3 |
| (10/3)*3 | Multiply result by 3 i.e., 3*3 | 9 |
| !5 | Logical NOT of non-zero value. | 0 |
| !5%3 | Modulus of 0 with 3. | 0 |
| (10/3)*3+!5%3 | Add both parts i.e., 9+0 | 9 |
Q: 14After execution the following statement what will be the value of variable a.
void main()
{
float a,b;
a=2;
b=3;
a*=b*=+28.5;
printf("%f",a);
}
Option C
The float variables a and b are first initialized with the values 2 and 3, respectively. The expression b *= +28.5 is evaluated first, which is equivalent to b = 3*28.5, resulting in b = 85.5. Next, the expression a *= b is evaluated, which is equivalent to a = 2*85.5, resulting in a = 171.
Finally, when printf("%f",a); is executed, the float value of a is printed in standard floating-point format as 171.000000.
Q: 15Find the final value of m in the given C code fragment.
int m=3,n=0;
n=m++ + ++m - --m;
Option A
In the given expression n = m++ + ++m - --m;, starting with m = 3, the value used by m++ is 3 and then m becomes 4, next ++m makes m equal to 5 and uses 5, and then --m reduces m to 4 and uses 4. After all operations, the final value of m becomes 4.
Note:
It is important to note that modifying the same variable multiple times within a single expression leads to undefined behavior in standard C, but in competitive exams, it is usually evaluated step by step as shown above.
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.