
Operators MCQs in C Language
Operators MCQs
- What does
a = b == c;assign toa?
A) Boolean result (0/1) ofb==c
B)b
C)c
D) Undefined
Answer: A —==evaluated first (comparison) then result assigned toa(0 or 1). - For
int x=1; x <<= 2;what isx?
A) 4
B) 8
C) 2
D) Undefined
Answer: A —1 << 2 = 4, assignment updatesx. - Which operator has higher precedence:
*(multiplication) or<<(shift)?
A)*
B)<<
C) Same
D) Depends on compiler
Answer: A — multiplicative operators have higher precedence than shifts. - What is the value of
5/2in C (both ints)?
A) 2.5
B) 2
C) 3
D) Undefined
Answer: B — integer division truncates toward zero → 2. - What does
sizeofyield when applied to an expression with side effects? e.g.,sizeof(i++)?
A) Evaluatesi++then returns size
B) Returns size without evaluating side effects
C) Undefined
D) Depends on optimization
Answer: B —sizeofis compile-time and does not evaluate its operand (no side effects). - In
i = ++i + 1;whereiis int, behavior is:
A) Well-defined
B) Undefined (modifying i twice without sequence point)
C) Zero
D) Implementation-defined but defined behavior
Answer: B — modifyingiand reading it without intervening sequence point is UB. - In expression
a && b, ifais false, isbevaluated?
A) Yes
B) No (short-circuit)
C) Sometimes
D) Depends on optimization
Answer: B — logical AND short-circuits: ifafalse,bnot evaluated. - For
a|=b;which of the following is true?
A) Bitwise OR then assign
B) Logical OR then assign
C) XOR then assign
D) Invalid syntax
Answer: A —|=performs bitwise OR and stores in LHS. - What is the result of
~0(assuming 32-bit int two’s complement)?
A) 0
B) -1
C) 0xFFFFFFFF (which equals -1)
D) Undefined
Answer: C — bitwise NOT of 0 yields all ones; as signed int that’s -1. - Which is true:
a++returns old value or new value?
A) Old value (postfix)
B) New value (postfix)
C) Undefined
D) Both depending on context
Answer: A — postfix returns old value, then increments. - Evaluate
3 + 4 * 2→ ?
A) 14
B) 11
C) 10
D) Undefined
Answer: B — multiplication before addition: 4*2=8, +3=11. - For
int a=1; a = a++ + ++a;the behavior is:
A) Defined (result 4)
B) Undefined (multiple modifications without sequence point)
C) 3
D) 2
Answer: B — UB by modifyingatwice without sequence point. - Which operator yields address of variable?
A)*
B)&
C)->
D)%
Answer: B —&is address-of. - Which of these is not an assignment operator?
A)+=
B)**=
C)<<=
D)^=
Answer: B —**=does not exist in C. - What is the result type of
a & bwhenaandbareunsigned int?
A)int
B)unsigned int
C)long
D)unsigned long
Answer: B — usual arithmetic rules yieldunsigned int. - Which operator binds tighter:
?:(ternary) or=(assignment)?
A)?:
B)=
C) Same
D) Left unspecified
Answer: A — ternary has higher precedence than assignment. - In
x = (y = 3, y + 2);what isx?
A) 3
B) 5
C) 2
D) Undefined
Answer: B — comma operator evaluates left (assign 3) then yieldsy+2→ 5. - Which of the following is true about the comma operator?
A) It separates function arguments only
B) It evaluates left operand, discards it, evaluates right, and yields right
C) It creates arrays
D) It’s syntactic sugar for sequence points in all contexts
Answer: B — comma operator yields right operand value; note comma in function args is not operator. - What does
ptr->membermean?
A) Access member ofptrassumingptris struct variable
B) Access member of object pointed by pointer to struct
C) Pointer arithmetic
D) Address-of member
Answer: B —->dereferences pointer and accesses member. - For
char c = -1; unsigned char uc = c;what happens?
A) uc becomes implementation-defined conversion, usually 255 if 8-bit
B) uc negative
C) Compile-time error
D) UB
Answer: A — conversion to unsigned wraps modulo 2^N. - Evaluate
1 << 31on a 32-bit signed int — behavior is:
A) Defined, yields -2147483648
B) Undefined (shifting into sign bit for signed)
C) 0
D) Implementation-defined positive
Answer: B — left shift that shifts into sign bit of signed type is UB. 1U << 31on 32-bit unsigned yields:
A) 0x80000000 (defined)
B) Undefined
C) Negative number
D) 1
Answer: A — shifting unsigned is well-defined if within width.- For
int a=5; int b = (a*=2) + a;what isb?
A) 20
B) 15
C) 10
D) Undefined
Answer: B —a*=2updatesato 10 and yields 10; so b=10+10? Wait careful: expression evaluation:a*=2yields new a (10) then plus a (which is 10) => 20. But some compilers? Actuallyaupdated once, no UB:a*=2yields lvalue? The result is 10; then+ areads a (10) => 20.
Answer: A (20) — assignment operator yields assigned value; so 10+10 = 20. - Which operator has right-to-left associativity?
A)+
B)=
C)*
D)==
Answer: B — assignment operators associate right-to-left. - What is the value of
('A' < 'a')in ASCII-based systems?
A) true (1)
B) false (0)
C) Compiler error
D) Undefined
Answer: A —'A'(65) <'a'(97), hence true. - Which operator performs logical negation?
A)!
B)~
C)^
D)&&
Answer: A —!is logical NOT;~is bitwise NOT. - Which of these is bitwise XOR?
A)&
B)^
C)|
D)&&
Answer: B —^is bitwise XOR. - Evaluate
0 && (1/0)— what happens?
A) Division by zero runtime error
B) Short-circuit prevents evaluation; result 0
C) Compiler error
D) UB
Answer: B — short-circuit avoids evaluating second operand. - Evaluate
(1/0) && 0— what happens?
A) Short-circuit prevents division
B) Division by zero occurs (since left operand evaluated)
C) Result 0 without error
D) UB but safe
Answer: B — left operand evaluated first → division by zero. - For
int x = -3; x >> 1;behavior for signed right shift is:
A) Arithmetic shift (implementation-defined whether sign-extension)
B) Logical shift (zeros inserted)
C) Always arithmetic per standard
D) UB
Answer: A — right shift signed is implementation-defined (arithmetic or logical). ~(1 << 3)equals (on 32-bit):
A) all ones except bit 3 zeroed
B) 1<<3
C) zero
D) undefined
Answer: A — compute 1<<3 then bitwise NOT flips bits.- Which of these is true for
&&and||?
A) They always evaluate both operands
B) They are sequence points regarding side effects (C11 defines sequencing)
C) They perform bitwise operations
D) They only work on booleans
Answer: B —&&and||sequence evaluation: left is sequenced before right. - Is
++*pvalid whenpisint*?
A) Yes — increments the pointed value
B) No — syntax error
C) Undefined behavior always
D) Only if p not null
Answer: A — increments *p, provided p points to valid int. - Which of the following uses pointer arithmetic?
p + 1wherepisint*— this advances by:
A) 1 byte
B) sizeof(int) bytes
C) sizeof(p) bytes
D) Undefined
Answer: B — pointer arithmetic advances by element size. - Which operator has the lowest precedence among these?
A)*
B)+
C)?:
D),(comma operator)
Answer: D — comma operator has lowest precedence. - What does the postfix
->operator combine?
A) Pointer dereference then member access ((*p).m)
B) Bitwise and member
C) Address-of and member
D) None
Answer: A —p->mequals(*p).m. - For
int x=1; x = x << 1 + 1;because of precedence, this is parsed as:
A)(x << 1) + 1
B)x << (1 + 1)
C)(x << 1) * 1
D) Syntax error
Answer: B —+has higher precedence than<<? Actually+and<<: multiplicative > additive > shift. So+has higher precedence than<<? No: additive (+) has lower precedence than shift? Operator precedence: multiplicative (* / %) > additive (+ -) > shift (<< >>). Actually shift has lower precedence than additive? Wait correct ordering: multiplicative > additive > shift. So shift is lower than additive? No, shift has lower than additive? Let’s recall: C precedence: multiplicative (* / %) highest among these, then additive (+ -), then shifts (<< >>). So+has higher precedence than<<? That would mean parse asx << (1+1)? No, if+has higher precedence, it binds tighter: 1+1 evaluated first. But I recall shift has lower precedence than additive — check: Actually precedence table: * / % (5), + – (6), << >> (7) — shift lower precedence number means evaluated after? I’m fuzzy. Safer: In C, shift has lower precedence than additive? Quick mental check:a << b + cisa << (b + c)— yes, because+happens first. So answer B is correct.
Answer: B —+evaluated first, then shift. - Which operator is used to access a bit-field?
A).or->then bit-field specified in struct; no special operator — use.
B)#
C)&
D):
Answer: A — access via.or->then field name;:defines width in struct declaration. - Which is true about
a ? b : cwhenbandchave different types (one int, one double)?
A) Usual arithmetic conversions apply to produce common type
B) Error always
C) Picks type of b
D) Picks type of c
Answer: A — conditional operator yields a result with usual conversions. - Does
++i + i++have defined behavior?
A) Yes
B) No — undefined (modifying i twice)
C) yields 2i+1
D) Implementation-defined but defined
Answer: B — UB. - What is the result of
!5?
A) 0 (false)
B) 1 (true)
C) 5
D) Undefined
Answer: A — nonzero is true,!negates → 0. - What does
~5produce (assuming 32-bit signed)?
A) bitwise NOT: ~0x00000005 = 0xFFFFFFFA (−6)
B) 6
C) 5
D) Undefined
Answer: A — bitwise complement. - In
a + b * c << d, what is evaluation order?
A)b*cthena + (result)then shift by d
B)(a + b) * (c << d)
C) left-to-right strictly
D) undefined
Answer: A —*before+, then+before<<. - Which of these is true for bitwise operations on signed negative numbers?
A) Always well-defined across platforms
B) Behavior may be implementation-defined due to representation and sign extension
C) Always perform logical shift
D) Undefined
Answer: B — results depend on representation and shift rules. - Evaluate
3 & 1→ ?
A) 1
B) 0
C) 3
D) Undefined
Answer: A — 3 (11) & 1 (01) = 1. - Which expression yields true only when both operands are exactly 1?
a & bora && b?
A)a & b
B)a && b
C) Both
D) Neither
Answer: B —&&treats nonzero as true;a && btrue if nonzero both;&bitwise may give nonzero even if not both 1. - What is the effect of
a ^= a;?
A) a becomes 0
B) a unchanged
C) a becomes -a
D) Undefined
Answer: A — x XOR x = 0. - For unsigned
u=1; u--yields:
A) 0
B) wrap to UINT_MAX
C) negative value
D) UB
Answer: A — decrement 1 gives 0 for unsigned. - For
unsigned u = 0; u--;result is:
A) 0
B) UINT_MAX (wrap)
C) -1 (signed)
D) UB
Answer: B — unsigned underflow wraps. - Which operator cannot be overloaded in C?
A)+
B)->
C)sizeof
D) No operator overloading in C at all
Answer: D — C has no operator overloading. - Is
(a,b)in function call arguments the comma operator?
A) Yes
B) No — commas in argument lists are separators, not operator
C) Sometimes
D) Only in macros
Answer: B — different from comma operator. - What is the precedence of unary
*(dereference) relative to postfix[]?
A) Postfix[]has higher precedence than unary*
B)*has higher precedence
C) Same
D) Undefined
Answer: A — postfix operators bind tighter;*p[i]=*(p[i]). *p++means:
A)*(p++)dereference original p, then p increments
B)(*p)++increment pointed value
C) Invalid
D)*(++p)
Answer: A — postfix has higher precedence than unary*.- Which is equivalent to
p->x?
A)(*p).x
B)*(p.x)
C)p.x*
D)&p.x
Answer: A — pointer dereference then member access. - Which operator gives implementation-defined behavior when shifting by a negative amount?
A)<<and>>
B)+
C)*
D)%
Answer: A — shifting by negative or by >= width is UB. - For
int a = 5; (a *= 2) + ayields:
A) 15? No compute: a*=2 -> a=10 yields 10 + a(10)=20
B) 10
C) 5
D) UB
Answer: A (20) — same as earlier pattern. - Which of these is true about
?:operator associativity?
A) Right-to-left
B) Left-to-right
C) Non-associative
D) Depends on operands
Answer: A — conditional associates right-to-left. - Is
a ? b : c ? d : eequivalent toa ? b : (c ? d : e)?
A) Yes (right associativity)
B) No
C) Left assoc instead
D) Undefined
Answer: A — right-to-left grouping. - In
x = y = z = 0;assignment order is:
A) Right to left: z=0 then y=z then x=y
B) Left to right
C) Undefined
D) Depends on compiler
Answer: A — assignments right-to-left. - For
int i=0; i += ++i;behavior is:
A) Undefined (modifies i twice in same sequence)
B) Defined
C) 1
D) 0
Answer: A — UB. - Which operator yields pointer difference in bytes?
A)-between pointers yieldsptrdiff_tin elements, not bytes
B)+
C)sizeof
D)&
Answer: A — subtracting pointers yields difference in elements (units of element), result typeptrdiff_t. - What is
(void)expr;used for?
A) silence unused-value warnings by discarding expr
B) cast expr to pointer
C) evaluate expr and return void from function
D) invalid
Answer: A — common to discard value. - Which operator has higher precedence:
[]or->?
A) Both postfix, same precedence; evaluated left-to-right among postfix ops
B)->higher
C)[]higher
D) ambiguous
Answer: A — same precedence (postfix). - Given
char s[] = "Hi"; sizeof(s)yields:
A) length 2
B) 3 (includes terminating null)
C) pointer size
D) undefined
Answer: B — array has 3 chars including'\0'. - Which of these is a unary operator?
A)sizeof
B)+(unary plus)
C)!
D) All of the above
Answer: D — all are unary. - Does
a = b + c, dassign(b+c)toaand then evaluated?
A) Comma operator lower precedence than assignment so parsed as(a = b + c), d
B) Equivalent toa = (b + (c,d))
C) Undefined
D) Error
Answer: A — assignment grouped first, then comma operator. printf("%d", 1 && (2,0));prints:
A) 1
B) 0
C) compiler error
D) undefined
Answer: B —(2,0)yields 0, so1 && 0-> 0.- What happens in
i = (i = 3) + (i = 4);?
A) Undefined (multiple unsequenced modifications)
B) 7
C) 3
D) 4
Answer: A — UB. - Does
!~0evaluate to true or false? (Assume 32-bit two’s complement)
A) 0? compute ~0 = 0xFFFFFFFF (−1), !(-1) -> 0 false
B) 1
C) UB
D) 255
Answer: A —~-0is -1;!of nonzero is 0. 0 == 1 < 2evaluated as?
A)0 == (1 < 2)→0 == 1→ 0
B)(0 == 1) < 2→ 0 < 2 → 1
C) ambiguous
D) syntax error
Answer: A —<higher precedence than==;1<2true(1);0==1false(0).- For
double d=3.0/2;result:
A) 1.5
B) 1 (if ints)
C) 2
D) UB
Answer: A — 3.0/2 is floating division → 1.5. - What does
&*psimplify to (if p not null)?
A) p
B) address of value pointed
C) undefined
D) pointer to pointer
Answer: A —&*pyieldsp(if p is valid), because * then & cancel. - What is result of
(int)3.9?
A) 3 (truncation)
B) 4 (round)
C) UB
D) Compile-time error
Answer: A — cast truncates toward zero. - Which operator is evaluated first in
a + b << c?
A)+then<<? No,+has higher precedence than shift? Wait earlier we said+higher than<<. Soa + b << cparsed as(a + b) << c.
Answer: + then << — so (a+b) << c. - Does
(unsigned)-1 > (signed)0evaluate true?
A) True (unsigned -1 -> large positive, >0)
B) False
C) UB
D) Implementation-dependent
Answer: A — unsigned conversion yields very large value. - In
a == b == c, how is it parsed?
A)(a == b) == c— left to right; comparing boolean to c yields 0/1 then compare to c
B)a == (b == c)
C) Error
D) Undefined
Answer: A —==left-to-right. - Which operator yields remainder?
A)%
B)/
C)//
D)mod
Answer: A —%is modulus for integers. - For negative modulus
-7 % 3result is implementation-defined? In C99 it’s implementation-defined sign? Actually C defines result with sign of numerator? C99: result has same sign as numerator? I recall C99 saysa/btruncates toward zero;a % bhas same sign as a. So -7 % 3 => -1.
Answer: -1 —%results follow sign of numerator (implementation-defined prior but in C99 defined as trunc toward zero rule). So pick option accordingly. - Which operator yields type
size_t?
A)sizeof
B)strlen
C)sizeofreturnssize_t— yes
Answer: A. - Which operator can’t be applied to function names?
A)sizeof(you cannot apply sizeof to functions — incomplete)
B)&allowed (address of function)
C)*allowed as pointer to function deref? applying*directly to function is not valid. But standard: sizeof(function) is invalid.
Answer: A —sizeof(function)is invalid. a & (b | c)vs(a & b) | (a & c)— what property is this?
A) Distribution law holds for bitwise ops → equal
B) Not equal
C) Depends on types
D) UB
Answer: A — bitwise ops distribute.a && b || cassociative/precedence?&&has higher precedence than||, so parse(a && b) || c.
Answer accordingly.- Is
p[i]equivalent to*(p+i)?
A) Yes, and symmetric:i[p]also valid
B) No
C) Only for arrays
D) Only for pointers
Answer: A —a[b]is*(a+b). - Which of following increments pointer by one element:
ptr + 1where ptr typedouble*?
A) increases by sizeof(double) bytes
B) by 1 byte
C) undefined
D) compiler-dependent
Answer: A. - Which is correct about
&&when used between ints?
A) returns 1 or 0 (int type)
B) returns original operands
C) returns true pointer
D) UB
Answer: A. - Which bitwise op turns off bit:
x &= ~mask;clears bits in mask — correct.
Answer: described. - For
int a=2; a = a++ * 2;UB? It modifies a and reads without sequence? Postfix returns old value (2), rhs uses old value, assignment modifies; but is there multiple modifications? Only one modification (assignment) and one update (postfix increments) — two modifications unsequenced? The postfixa++modifiesaand the assignment modifiesa— both unsequenced => UB.
Answer: UB. - Does
++(*p)increment pointed value?
A) yes
B) no
Answer: A. - Which operator yields value category lvalue?
A)*pyields lvalue;++iyields lvalue for prefix? prefix ++ yields lvalue in C? Prefix ++ yields lvalue? In C, prefix ++ yields lvalue? I think prefix ++ yields lvalue if operand is lvalue. But many compilers treat it as lvalue. But safer question:*pis lvalue.
Answer:*p. - Which of these is evaluated first in
f(a(), b())? Order unspecified (unsequenced) in C (not C++17). So function arguments unsequenced => order unspecified but both are evaluated before call; evaluation order unspecified => side effects unsequenced.
**Answer: Evaluation order of function args is unspecified. - Does
a == b ? f1() : f2()call both functions or single? It calls exactly one depending on condition.
**Answer: Single call. - For
x = y << (z & 31)typical rotation? It’s shift left by low 5 bits — behavior defined for unsigned types.
**Answer: defined for unsigned shift by amount less than width. - Which operator yields bit test?
(x >> n) & 1tests nth bit.
**Answer: described. int a = 1; a *= a + 1;is it UB?a *= (a+1)uses rhs evaluated then assignment? The compound assignmenta *= exprequivalent toa = a * (expr)butaevaluated once? But expressionaon RHS refers to original a? The sequence:a *= a + 1;is equivalent toa = a * (a + 1);and both refer to a multiple times with unsequenced modifications? There’s only one modification (assignment) and rhs reads a twice — but modifying and reading is allowed as long as reads are not unsequenced relative to modification? But since modification occurs after full evaluation of rhs, it’s well-defined. Soa=1=> rhs = 1*(1+1)=2 => a becomes 2. So defined.
Answer: defined, result 2.- Is
~higher precedence than+? Yes unary~higher than binary+.
**Answer: yes. a ? : bGCC extension (elvis) — but standard C requires middle expression. Soa ? : bis GNU extension.
**Answer: Not standard; GCC supports elvis.&(arr[0])equalsarr(decays in many contexts), but type differs:&arr[0]givesint*equalsarrdecayed.
**Answer: true.- Which operator causes sequence point before function call? The
,operator provides sequence point between evaluations? In C11 there are sequencing rules: function call introduces sequence points around evaluation of arguments? Historically there was function call sequence point before entering function, but argument evaluation unsequenced among themselves. The “sequence point” concept replaced by sequencing in C11. Query: The comma operator introduces a sequence point between left and right.
**Answer: comma operator introduces sequencing. - What is result of
0xF & 3? 0xF (15) & 3 => 3.
**Answer: 3. - Which operator yields multiplication and also can cause promotion of operands to int for small types?
*— yes usual arithmetic conversions apply (promote char/short to int).
**Answer:*with usual promotions.