Which of the following ‘C’ language arithmetic expressions has logical error?
2017
Which of the following ‘C’ language arithmetic expressions has logical error?
- A.
-13 % -5 + 3;
- B.
4 / (-10 % -2) / 3;
- C.
3 / (-13 % -5) / 3;
- D.
-5 % 3 / 13;
Attempted by 829 students.
Show answer & explanation
Correct answer: B
In option B, the inner expression (-10 % -2) evaluates to 0 because -10 is perfectly divisible by -2. This results in 4 / 0 / 3. Dividing an integer by zero causes a critical runtime/logical crash (Division by Zero error) in C.
Correct Option: B