Which of the following ‘C’ language arithmetic expressions has logical error?

2017

Which of the following ‘C’ language arithmetic expressions has logical error?

  1. A.

    -13 % -5 + 3;

  2. B.

    4 / (-10 % -2) / 3;

  3. C.

    3 / (-13 % -5) / 3;

  4. 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

Explore the full course: Coal India Management Trainee