ProgrammingVery hard

Which declaration creates a 3 x 3 identity matrix with C99 designators?

  1. A. int id[3][3] = {1, 1, 1};
  2. B. int id[3][3] = {[0] = 1, [1] = 1, [2] = 1};
  3. C. int id[3][3] = {{1}, {0, 1}, {0, 0, 1}};
  4. D. int id[3][3] = {[0][0] = 1, [1][1] = 1, [2][2] = 1};

Correct answer: D. int id[3][3] = {[0][0] = 1, [1][1] = 1, [2][2] = 1};

Each diagonal cell is set by its designator and the rest are zero. The other forms set the wrong cells or the wrong type of initialiser.

More C Programming questions

Exams that ask this topic