Here are the most important Multiple choice questions on Operators and Expressions in C programming. The questions are from the following sections,
- Operators in C
- Expressions and Operator Precedence in C
- Type casting in C
- Which of the following is a valid expression in C?
- int basic_pay = 23000;
- int basic_pay = 23,000;
- int basic pay = 23000;
- int $basic_pay = 23000;
Show Answer
Answer: A
Variable names cannot contain white spaces, commas, or $
- Which of the following arithmetic operator takes only integer operands?
- +
- –
- /
- %
Show Answer
Answer: D
The modulo division (%) operator produces the remainder of an integer division.
- Which of the following operator has the lowest priority?
- &&
- +
- *
- !==
Show Answer
Answer: A
- Which among the following operator has the highest priority?
- Comma operator
- Conditional operator
- Relational operator
- Unary plus operator
Show Answer
- Which of the following statement is true?
- All arithmetic operators have the same level of precedence.
- The modulus operator % can be used only with integers.
- A unary expression consists of only one operand with no operators.
- The operators <=, >=, and != all enjoy the same level of priority.
Show Answer
Answer: B
The modulus operator % can be used only with integers.
- What will be the output for the following C code?
- 2
- 1
- 3
- Compile-time error
#include <stdio.h> int main() { int n = 8; n = n / 3; printf("%d", n); return 0; }
Show Answer
Answer: A
2
- What is the correct order of precedence of arithmetic operators from highest to lowest?
- %, *, /, +, –
- -, +, *, /, %
- %, +, -, *, /
- +, – , %, *, /
Show Answer
Answer: A
- What will be the output for the following C code?
- Value of x is 3
- Value of x is 2
- Value of x is 1
- Compile-time error
#include <stdio.h> void main() { int y = 4; int x = 9 % 2 * 4 / 2; printf("Value of x is %d", x); }
Show Answer
Answer: A
Value of x is 2
- Which of the following is not an arithmetic operation?
- a*=5;
- a/=5;
- a!=5;
- a%=5;
Show Answer
Answer: C
- What will be the output for the following C code?
- 10.6
- 10
- 11
- 16
#include <stdio.h> int main() { int a = 8; double b = 2.6; int c; c = a + b; printf("%d", c); }
Show Answer
Answer: A
10
- What is the result of a logical or relational expression in C?
- 0 or 1
- True or false
- 0 if false and a positive number if true.
- T or F
Show Answer
Answer: A
- What will be the output for the following C code?
- 23
- 15
- Undefined behavior
- 21
#include <stdio.h> int main() { int x = 5, y = 2; x *= x - y; printf("%d", x); return 0; }
Show Answer
Answer: B
15
- What will be the output for the following C code?
- 4
- 2
- 1
- Undefined behavior
#include <stdio.h> int main() { int x = 4, y = 2; x /= x / y; printf("%d\n", x); return 0; }
Show Answer
Answer: B
2
- What will be the output for the following C code?
- Compile-time error
- Yes
- No
- Nothing
#include <stdio.h> void main() { int x = 0; if (x = 0) printf("Yes"); else printf("No"); }
Show Answer
Answer: C
No
- What is the use of sizeof() operator?
- To get the size of data types or variables in bytes
- To get the size of variables only
- To get the size of the structure only
- None of the above
Show Answer
Answer: A
- What is the operator ‘:?’ called?
- If-Else operator
- Ternary operator
- Logical operator
- Comparison operator
Show Answer
Answer: A
The ‘:?’ operator is called the conditional operator or ternary operator.
- Which of the following are true regardless of the implementation?
sizeof(int)
is not less thansizeof(long)
sizeof(int)
equalssizeof(unsigned)
sizeof(double)
sizeof(float)
- Both B and C
Show Answer
Answer: D
In C, sizeof(int)
is not less than sizeof(long)
and sizeof(int)
equals sizeof(unsigned)
regardless of the implementation,
- If y is of integer type then the expressions
3 * ( y -8 ) / 9
and(y - 8) /9 * 3
- must yield the same value
- must yield different values
- may or may not yield the same value
- none of the above
Show Answer
Answer: C
In C, sizeof(int)
is not less than sizeof(long)
and sizeof(int)
equals sizeof(unsigned)
regardless of the implementation,
- Integer division results in
- truncation
- rounding
- overflow
- none of the above
Show Answer
Answer: A
For example, integer division of 8 and 3 will result in 2.
- In an expression involving
||
operator, evaluation- will be stopped if one of its components evaluates to false
- will be stopped if one of its components evaluates to true
- takes place from left to right
- Both B and C
Show Answer
Answer: D
- Implicit type conversion takes place
- across an assignment operator.
- if an operator has operands of different data types.
- Both A and B
- None of the above.
Show Answer
Answer: C
- Choose the correct statements
- Casting refers to implicit type conversion
- Coercion refers to implicit type conversion
- Casting refers to explicit type conversion
- Both B and C
Show Answer
Answer: D
- Pick the operators that associate from the left
- +
- ,
- ==
- All of above
Show Answer
Answer: D
- Pick the operators that associate from the right
- ?:
- +=
- =
- All of above
Show Answer
Answer: D
- Pick the operators whose meaning is context-dependent.
- *
- #
- &
- All of above
Show Answer
Answer: D
x -= y + 1;
means- x = x – y + 1
- x = -x – y – 1
- x = -x + y + 1
- x = x – y – 1
Show Answer
Answer: D
x -= y + 1 is equivalent to x = x – (y + 1). That is x = x – y – 1.
- Which of the following comments about the ++ operator are correct?
- It is a unary operator
- The operand can come before or after the operator
- It cannot be applied to an expression
- All of above
Show Answer
Answer: D
- The expression
evaluates to4 + 6 / 3 * 2 - 2 + 7 % 3
- 3
- 4
- 6
- 7
Show Answer
Answer: D
- If a=5 and b=2 then
printf("%d", a+++b);
will?- results in a syntax error
- print 8
- print 10
- None of the above
Show Answer
Answer: B
The compiler will tokenize a+++b as a, ++, +, b. So, a+++b is equivalent a++ + b, which evaluates to 8.
- The statement
printf("%d", (a++));
will print- the current value of a
- the value of a + 1
- an error message
- garbage
Show Answer
Answer: A
- The statement
printf("%d", ++5);
will print- 5
- 6
- an error message
- garbage
Show Answer
Answer: C
- The statement
printf("%d", sizeof(""));
will print- 0
- 1
- an error message
- garbage value
Show Answer
Answer: B
- The ascending order of precedence of the bit-wise operators &, ^, and | is
- & ^ |
- ^ & |
- | ^ &
- & | ^
Show Answer
Answer: A
for the last question the order of precedence is &^| but in answer &|^ how it will come?
We have corrected the mistake in the original post to reflect the correct order of precedence for the operators & (bitwise AND), ^ (bitwise XOR), and | (bitwise OR) in C programming language, which is &^|, with the bitwise AND being evaluated first, followed by the bitwise XOR, and then finally the bitwise OR.
We’re sorry for any confusion that this mistake may have caused. We truly appreciate your attention to detail and for bringing this matter to our attention, thereby assisting us in enhancing the precision of our content.