Operators Question Bank for C-CAT
Topic-wise Operators MCQs for CDAC C-CAT preparation with answers and explanations.
Show Answer & Explanation
Correct Answer: B - Unary
Unary operators have higher precedence than arithmetic and relational operators.
What will be the output?
int x = 5;
printf("%d", x++);Show Answer & Explanation
Correct Answer: C - 5
Post-increment prints the value first, then increments.
What will be the output?
int x = 5;
printf("%d", ++x);Show Answer & Explanation
Correct Answer: D - 6
Pre-increment increments the value first, then prints.
Show Answer & Explanation
Correct Answer: B - ==
== compares two values for equality.
What is the output?
printf("%d", 10 > 5 && 3 < 1);Show Answer & Explanation
Correct Answer: B - 0
10 > 5 is true, 3 < 1 is false, so true && false = false (0).
Show Answer & Explanation
Correct Answer: B - &
& performs bitwise AND operation.
What will be the output?
printf("%d", 5 & 3);Show Answer & Explanation
Correct Answer: D - 1
5 (101) & 3 (011) = 001 which is 1.
Show Answer & Explanation
Correct Answer: B - =
= assigns value to a variable.
What will be the output?
printf("%d", 10 / 4);Show Answer & Explanation
Correct Answer: D - 2
Integer division truncates decimal part.
Show Answer & Explanation
Correct Answer: D - =
Assignment operator has right-to-left associativity.
What is the output?
int a = 10, b = 20;
printf("%d", a > b ? a : b);Show Answer & Explanation
Correct Answer: C - 20
Ternary operator returns the larger value.
Show Answer & Explanation
Correct Answer: D - ?:
?: takes three operands.
What will be the output?
printf("%d", 5 | 3);Show Answer & Explanation
Correct Answer: C - 7
5 (101) | 3 (011) = 111 which is 7.
Show Answer & Explanation
Correct Answer: C - ~
~ performs bitwise NOT operation.
What will be the output?
printf("%d", !0);Show Answer & Explanation
Correct Answer: B - 1
!0 is logical NOT of false, resulting in true (1).
Show Answer & Explanation
Correct Answer: D - ->
-> is used to access members via pointer.
What is the output?
printf("%d", 8 >> 2);Show Answer & Explanation
Correct Answer: A - 2
Right shift by 2 divides by 4.
Show Answer & Explanation
Correct Answer: B - &
& returns address of variable.
What will be the output?
printf("%d", 5 ^ 3);Show Answer & Explanation
Correct Answer: C - 6
5 (101) XOR 3 (011) = 110 which is 6.
Show Answer & Explanation
Correct Answer: B - =
Assignment operator has lower precedence than arithmetic operators.
What will be the output?
int a = 5, b = 10;
printf("%d", a + b * 2);Show Answer & Explanation
Correct Answer: A - 25
Multiplication has higher precedence than addition: 10*2 + 5 = 25.
What will be the output?
printf("%d", (5 + 10) * 2);Show Answer & Explanation
Correct Answer: C - 30
Parentheses have highest precedence.
Show Answer & Explanation
Correct Answer: C - &&
&& is logical AND operator.
What will be the output?
int x = 1;
printf("%d", x++ + ++x);Show Answer & Explanation
Correct Answer: C - Undefined
Modifying variable more than once between sequence points leads to undefined behavior.
What will be the output?
printf("%d", 0 || 5);Show Answer & Explanation
Correct Answer: D - 1
Logical OR returns 1 if any operand is true.
Show Answer & Explanation
Correct Answer: D - |
Bitwise OR combines bits.
What will be the output?
printf("%d", ~1);Show Answer & Explanation
Correct Answer: A - -2
~1 inverts all bits; result depends on two's complement representation.
Show Answer & Explanation
Correct Answer: A - =
Assignment operator has the lowest precedence.
What will be the output?
int a = 10;
printf("%d", a += 5);Show Answer & Explanation
Correct Answer: A - 15
a += 5 is equivalent to a = a + 5.
Show Answer & Explanation
Correct Answer: A - ==
== is a relational operator, not assignment.
What will be the output?
printf("%d", 5 << 1);Show Answer & Explanation
Correct Answer: B - 10
Left shift by 1 multiplies by 2.
Show Answer & Explanation
Correct Answer: A - *
* dereferences a pointer.
What will be the output?
int a = 0;
printf("%d", !a);Show Answer & Explanation
Correct Answer: B - 1
Logical NOT of 0 is 1.
Show Answer & Explanation
Correct Answer: A - !=
!= checks not equal condition.
What will be the output?
printf("%d", 4 & 1);Show Answer & Explanation
Correct Answer: B - 0
4 (100) & 1 (001) = 000.
Show Answer & Explanation
Correct Answer: A - =
Assignment operator has right-to-left associativity.
What will be the output?
printf("%d", 10 % 3);Show Answer & Explanation
Correct Answer: D - 1
Modulus operator returns remainder.
Show Answer & Explanation
Correct Answer: D - ,
Comma operator evaluates expressions left to right.
What will be the output?
printf("%d", (5 > 3) + (2 > 4));Show Answer & Explanation
Correct Answer: D - 1
True is 1 and false is 0 -> 1 + 0 = 1.
Show Answer & Explanation
Correct Answer: B - ++
++ operates on a single operand.
What is the output of the following code?
int a = 5;
int b = a++ + ++a;
printf("%d", b);Show Answer & Explanation
Correct Answer: C - Undefined behavior
Modifying a variable more than once between two sequence points (here, using both a++ and ++a in the same expression) results in undefined behavior according to the C standard. The output is unpredictable and compiler-dependent.
x & (x - 1) do when x is a positive integer?Show Answer & Explanation
Correct Answer: C - Clears the rightmost set bit of x
The expression x & (x - 1) clears (turns off) the lowest set bit of x. For example, if x = 12 (1100 in binary), x-1 = 11 (1011), and 1100 & 1011 = 1000 (8). This is commonly used to check if a number is a power of 2 (result is 0 if it is).
5 | 3 in C?Show Answer & Explanation
Correct Answer: A - 7
The bitwise OR operator (|) compares each bit of the operands and returns 1 if at least one bit is 1. 5 in binary is 101, and 3 is 011. Performing OR: 101 | 011 = 111 = 7 in decimal.
What is the output?
int x = 10;
int y = (x > 5) ? (x * 2) : (x + 2);
printf("%d", y);Show Answer & Explanation
Correct Answer: D - 20
The ternary operator evaluates the condition (x > 5). Since x is 10, which is greater than 5, the condition is true, so the expression evaluates to (x * 2) = 20.
~0 in C (assuming 32-bit int)?Show Answer & Explanation
Correct Answer: B - -1
The bitwise NOT operator (~) flips all bits. ~0 flips all 32 bits from 0 to 1, resulting in 0xFFFFFFFF. In two's complement representation, this value is -1.
What is the output of this code?
int a = 3, b = 2;
printf("%d", a ^ b);Show Answer & Explanation
Correct Answer: A - 1
The XOR operator (^) returns 1 for each bit position where the operands differ. 3 in binary = 11, 2 in binary = 10. XOR: 11 ^ 10 = 01 = 1 in decimal.
Show Answer & Explanation
Correct Answer: C - () (function call)
The function call operator (), array subscript [], member access (. and ->), and postfix ++ / -- have the highest precedence (level 1) in C. Among the given options, () has the highest precedence.
What is the output?
int x = 8;
printf("%d", x >> 2);Show Answer & Explanation
Correct Answer: A - 2
The right shift operator (>>) shifts bits to the right. Shifting 8 (binary 1000) right by 2 positions gives 10 in binary, which is 2. Right shifting by n positions is equivalent to integer division by 2n, so 8 / 4 = 2.
What will this code output?
int a = 5, b = 0;
int c = a && b;
int d = a || b;
printf("%d %d", c, d);Show Answer & Explanation
Correct Answer: C - 0 1
The logical AND (&&) returns 1 only if both operands are non-zero. Since b is 0, a && b = 0. The logical OR (||) returns 1 if at least one operand is non-zero. Since a is 5 (non-zero), a || b = 1. Output: 0 1.
What is the output of the following?
int x = 1;
printf("%d", x << 4);Show Answer & Explanation
Correct Answer: A - 16
The left shift operator (<<) shifts bits to the left. 1 in binary is 0001. Shifting left by 4 gives 10000, which is 16. Left shifting by n positions is equivalent to multiplying by 2n, so 1 × 24 = 16.