Back to Practice C Programming

Operators - Practice MCQs for CCAT

50 Questions Section B: Programming C Programming

Operators Question Bank for C-CAT

Topic-wise Operators MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.
Which operator has the highest precedence in C?
AArithmetic
BUnary
CAssignment
DRelational
Show Answer & Explanation

Correct Answer: B - Unary

Unary operators have higher precedence than arithmetic and relational operators.

Q2.

What will be the output?

int x = 5;
printf("%d", x++);
A4
B6
C5
DError
Show Answer & Explanation

Correct Answer: C - 5

Post-increment prints the value first, then increments.

Q3.

What will be the output?

int x = 5;
printf("%d", ++x);
A4
B5
CError
D6
Show Answer & Explanation

Correct Answer: D - 6

Pre-increment increments the value first, then prints.

Q4.
Which operator is used to check equality?
A=
B==
C!=
D<=
Show Answer & Explanation

Correct Answer: B - ==

== compares two values for equality.

Q5.

What is the output?

printf("%d", 10 > 5 && 3 < 1);
A1
B0
CTrue
DFalse
Show Answer & Explanation

Correct Answer: B - 0

10 > 5 is true, 3 < 1 is false, so true && false = false (0).

Q6.
Which operator is used for bitwise AND?
A&&
B&
C|
D^
Show Answer & Explanation

Correct Answer: B - &

& performs bitwise AND operation.

Q7.

What will be the output?

printf("%d", 5 & 3);
A7
B3
C5
D1
Show Answer & Explanation

Correct Answer: D - 1

5 (101) & 3 (011) = 001 which is 1.

Q8.
Which operator is used to assign value?
A==
B=
C:
D->
Show Answer & Explanation

Correct Answer: B - =

= assigns value to a variable.

Q9.

What will be the output?

printf("%d", 10 / 4);
ACompilation error
B2.5
C3
D2
Show Answer & Explanation

Correct Answer: D - 2

Integer division truncates decimal part.

Q10.
Which operator has right-to-left associativity?
A+
B*
C&&
D=
Show Answer & Explanation

Correct Answer: D - =

Assignment operator has right-to-left associativity.

Q11.

What is the output?

int a = 10, b = 20;
printf("%d", a > b ? a : b);
A10
B0
C20
DError
Show Answer & Explanation

Correct Answer: C - 20

Ternary operator returns the larger value.

Q12.
Which operator is known as ternary operator?
A::
B&&
C||
D?:
Show Answer & Explanation

Correct Answer: D - ?:

?: takes three operands.

Q13.

What will be the output?

printf("%d", 5 | 3);
A1
B3
C7
D5
Show Answer & Explanation

Correct Answer: C - 7

5 (101) | 3 (011) = 111 which is 7.

Q14.
Which operator is used to invert bits?
A!
B^
C~
D&
Show Answer & Explanation

Correct Answer: C - ~

~ performs bitwise NOT operation.

Q15.

What will be the output?

printf("%d", !0);
A0
B1
CTrue
DError
Show Answer & Explanation

Correct Answer: B - 1

!0 is logical NOT of false, resulting in true (1).

Q16.
Which operator is used to access structure members using pointer?
A.
B&
C*
D->
Show Answer & Explanation

Correct Answer: D - ->

-> is used to access members via pointer.

Q17.

What is the output?

printf("%d", 8 >> 2);
A2
B1
C4
D8
Show Answer & Explanation

Correct Answer: A - 2

Right shift by 2 divides by 4.

Q18.
Which operator is used to get address of variable?
A*
B&
C#
D%
Show Answer & Explanation

Correct Answer: B - &

& returns address of variable.

Q19.

What will be the output?

printf("%d", 5 ^ 3);
A1
B8
C6
D7
Show Answer & Explanation

Correct Answer: C - 6

5 (101) XOR 3 (011) = 110 which is 6.

Q20.
Which of the following has lowest precedence?
A*
B=
C+
D()
Show Answer & Explanation

Correct Answer: B - =

Assignment operator has lower precedence than arithmetic operators.

Q21.

What will be the output?

int a = 5, b = 10;
printf("%d", a + b * 2);
A25
B30
C20
D15
Show Answer & Explanation

Correct Answer: A - 25

Multiplication has higher precedence than addition: 10*2 + 5 = 25.

Q22.

What will be the output?

printf("%d", (5 + 10) * 2);
A25
B20
C30
D15
Show Answer & Explanation

Correct Answer: C - 30

Parentheses have highest precedence.

Q23.
Which operator is used to test multiple conditions together?
A&
B|
C&&
D^
Show Answer & Explanation

Correct Answer: C - &&

&& is logical AND operator.

Q24.

What will be the output?

int x = 1;
printf("%d", x++ + ++x);
A3
B4
CUndefined
DCompilation error
Show Answer & Explanation

Correct Answer: C - Undefined

Modifying variable more than once between sequence points leads to undefined behavior.

Q25.

What will be the output?

printf("%d", 0 || 5);
A0
BError
C5
D1
Show Answer & Explanation

Correct Answer: D - 1

Logical OR returns 1 if any operand is true.

Q26.
Which operator is used to combine bits?
A&&
B!
C||
D|
Show Answer & Explanation

Correct Answer: D - |

Bitwise OR combines bits.

Q27.

What will be the output?

printf("%d", ~1);
A-2
B-1
C0
D1
Show Answer & Explanation

Correct Answer: A - -2

~1 inverts all bits; result depends on two's complement representation.

Q28.
Which operator is evaluated last?
A=
B*
C+
D()
Show Answer & Explanation

Correct Answer: A - =

Assignment operator has the lowest precedence.

Q29.

What will be the output?

int a = 10;
printf("%d", a += 5);
A15
B10
C5
DError
Show Answer & Explanation

Correct Answer: A - 15

a += 5 is equivalent to a = a + 5.

Q30.
Which of the following is NOT an assignment operator?
A==
B*=
C/=
D+=
Show Answer & Explanation

Correct Answer: A - ==

== is a relational operator, not assignment.

Q31.

What will be the output?

printf("%d", 5 << 1);
A5
B10
C2
D1
Show Answer & Explanation

Correct Answer: B - 10

Left shift by 1 multiplies by 2.

Q32.
Which operator is used for pointer dereferencing?
A*
B&
C->
D.
Show Answer & Explanation

Correct Answer: A - *

* dereferences a pointer.

Q33.

What will be the output?

int a = 0;
printf("%d", !a);
A0
B1
CTrue
DError
Show Answer & Explanation

Correct Answer: B - 1

Logical NOT of 0 is 1.

Q34.
Which operator checks inequality?
A!=
B==
C=
D<>
Show Answer & Explanation

Correct Answer: A - !=

!= checks not equal condition.

Q35.

What will be the output?

printf("%d", 4 & 1);
A1
B0
C4
D5
Show Answer & Explanation

Correct Answer: B - 0

4 (100) & 1 (001) = 000.

Q36.
Which operator is evaluated from right to left?
A=
B*
C+
D%
Show Answer & Explanation

Correct Answer: A - =

Assignment operator has right-to-left associativity.

Q37.

What will be the output?

printf("%d", 10 % 3);
AError
B3
C0
D1
Show Answer & Explanation

Correct Answer: D - 1

Modulus operator returns remainder.

Q38.
Which operator is used to separate expressions?
A;
B.
C:
D,
Show Answer & Explanation

Correct Answer: D - ,

Comma operator evaluates expressions left to right.

Q39.

What will be the output?

printf("%d", (5 > 3) + (2 > 4));
A0
BError
C2
D1
Show Answer & Explanation

Correct Answer: D - 1

True is 1 and false is 0 -> 1 + 0 = 1.

Q40.
Which of the following is a unary operator?
A+
B++
C*
D&&
Show Answer & Explanation

Correct Answer: B - ++

++ operates on a single operand.

Q41.

What is the output of the following code?

int a = 5;
int b = a++ + ++a;
printf("%d", b);
A11
B12
CUndefined behavior
D10
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.

Q42.
What does the expression x & (x - 1) do when x is a positive integer?
ASets the rightmost bit of x
BToggles all bits of x
CClears the rightmost set bit of x
DReturns the complement of x
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).

Q43.
What is the value of the expression 5 | 3 in C?
A7
B1
C8
D15
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.

Q44.

What is the output?

int x = 10;
int y = (x > 5) ? (x * 2) : (x + 2);
printf("%d", y);
A12
B5
C10
D20
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.

Q45.
What is the result of ~0 in C (assuming 32-bit int)?
A0
B-1
C1
D2147483647
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.

Q46.

What is the output of this code?

int a = 3, b = 2;
printf("%d", a ^ b);
A1
B2
C3
D5
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.

Q47.
Which operator has the highest precedence in C?
A* (multiplication)
B++ (post-increment)
C() (function call)
D& (address-of)
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.

Q48.

What is the output?

int x = 8;
printf("%d", x >> 2);
A2
B4
C16
D32
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.

Q49.

What will this code output?

int a = 5, b = 0;
int c = a && b;
int d = a || b;
printf("%d %d", c, d);
A1 1
B1 0
C0 1
D0 0
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.

Q50.

What is the output of the following?

int x = 1;
printf("%d", x << 4);
A16
B8
C4
D32
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.

Showing 1-10 of 50 questions