Understanding Operators and Expressions in C Programming In Chapter 3, we explore operators and expressions, which form the backbone of logical and mathematical operations in C programming. Key topics include arithmetic operators such as +, -, *, /, and %, which perform basic calculations. Relational operators (==, !=, >, <, >=, <=) allow for value comparisons, while logical operators (&&, ||, !) help create complex conditions. Bitwise operators like &, |, and ^ work on binary values for bit manipulation. This chapter also covers assignment operators (+=, -=, etc.), increment/decrement operators (++, --), and expression precedence, ensuring a solid foundation in C’s operational capabilities.
Chapter 3: Operators and Expressions
Arithmetic Operators
What does the operator % do in C?
a) Multiplies two numbers
b) Divides two numbers
c) Gives the remainder of division
d) Adds two numbers
What will the output of 10 / 3 be in C?
a) 3.33
b) 3
c) 4
d) 3.0
What is the result of 5 * 3 + 4?
a) 15
b) 17
c) 19
d) 9
What is the output of 20 - 5 * 2?
a) 10
b) 30
c) 15
d) 5
What is the result of 9 % 2 in C?
a) 0
b) 2
c) 1
d) 4.5
Relational Operators
Which operator is used to check if two values are equal?
a) =
b) ==
c) !==
d) <=
What does the expression 5 > 3 return?
a) 5
b) 3
c) 1
d) 0
What is the output of 6 >= 6?
a) true
b) 1
c) false
d) 0
Which of these will return true if a = 3 and b = 4?
a) a > b
b) a < b
c) a >= b
d) a == b
What will 7 != 5 evaluate to?
a) 0
b) 1
c) false
d) None of these
Logical Operators
Which of the following is a logical operator?
a) &
b) &&
c) %
d) |=
What is the result of 1 && 0?
a) 0
b) 1
c) true
d) false
What will !0 evaluate to?
a) 0
b) 1
c) null
d) error
If a = 5 and b = 0, what does (a || b) return?
a) 5
b) 1
c) 0
d) false
Which expression is true if x = 1 and y = 0?
a) x && y
b) x || y
c) !x
d) y && x
Bitwise Operators
What does the operator & do in bitwise operations?
a) OR operation
b) AND operation
c) NOT operation
d) XOR operation
What is the result of 5 & 3 in binary?
a) 101
b) 1
c) 111
d) 0
Which bitwise operator is used for negation?
a) ~
b) &
c) ^
d) |
What is the result of 4 | 1?
a) 0
b) 5
c) 4
d) 1
Which of the following shifts bits to the left?
a) <<
b) >>
c) &
d) |
Assignment Operators
What does a += 2 mean?
a) a = a + 2
b) a = 2
c) a + 2
d) Increment by 2
If a = 3, what is the value of a *= 4?
a) 3
b) 12
c) 1
d) 7
What is the shorthand for b = b - 5?
a) b+5
b) b=-5
c) b-=5
d) b=-+5
What is the output of a = 5; a /= 2;?
a) 2.5
b) 2
c) 5
d) 0
Which of the following is not an assignment operator?
a) +=
b) /=
c) *=
d) =+
Increment and Decrement Operators
What is the result of int a = 5; a++;?
a) 5
b) 6
c) 7
d) 4
If x = 4, what does ++x mean?
a) x = x + 1
b) x = x - 1
c) x = 1
d) x = x
What is the difference between x++ and ++x?
a) No difference
b) x++ increments after, ++x increments before
c) ++x increments after, x++ increments before
d) They both decrement
What is the output of int a = 7; a--;?
a) 6
b) 7
c) 5
d) 8
If y = 10, what does --y result in?
a) 9
b) 10
c) 11
d) 0
Expressions and Precedence
What is operator precedence?
a) Order of operations
b) Priority of operator evaluation
c) Order of code lines
d) Importance of variables
What has higher precedence, * or +?
a) +
b) *
c) Same precedence
d) No precedence
Which operator has the lowest precedence?
a) &&
b) ||
c) ==
d) +
What is the result of 5 + 2 * 3?
a) 21
b) 11
c) 9
d) 15
What is the output of 4 * 2 + 3?
a) 14
b) 11
c) 10
d) 7
Arithmetic Operators (Continued)
What is the value of 7 % 4?
a) 3
b) 4
c) 1
d) 0
If a = 10 and b = 20, what is the result of a * b + a / b?
a) 10
b) 20
c) 200.5
d) 200
Relational Operators (Continued)
Which operator would you use to check if x is not equal to y?
a) =
b) !=
c) <>
d) ^
If x = 10 and y = 5, what is the result of (x > y) && (x < 15)?
a) 1
b) 0
c) True
d) False
Which of the following is not a relational operator?
a) ==
b) &&
c) !=
d) <
Logical Operators (Continued)
Which logical operator is used to combine multiple conditions to check if both are true?
a) ||
b) &&
c) !
d) &=
In C, what does the expression (5 > 3) || (2 < 1) return?
a) true
b) 0
c) 1
d) false
What does !(5 == 5) evaluate to?
a) 5
b) 0
c) 1
d) -1
If a = 1 and b = 0, what is the result of !(a && b)?
a) 1
b) 0
c) true
d) false
Bitwise Operators (Continued)
Which operator is used for the bitwise XOR operation?