ProgrammingHardProduct-company MCQ pattern

In C, with int i = 1, a[5];, which statement has undefined behaviour?

  1. A. i = i + 1;
  2. B. if (i++ && i++) i = 0;
  3. C. a[i] = i++;
  4. D. i++, i++;

Correct answer: C. a[i] = i++;

In a[i] = i++ the read of i inside a[i] and the side effect of i++ are unsequenced, which is undefined in C. && and the comma operator both put a sequence point between their operands, so the other two are well-defined.

More C Programming questions

Exams that ask this topic