ProgrammingVery hard
Which declaration creates a 3 x 3 identity matrix with C99 designators?
- A. int id[3][3] = {1, 1, 1};
- B. int id[3][3] = {[0] = 1, [1] = 1, [2] = 1};
- C. int id[3][3] = {{1}, {0, 1}, {0, 0, 1}};
- 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
- For n = 10^5 cells in a 1D array viewed as a 316 x 317 grid, what is the total cell count?
- A matrix has R rows and C columns with R = 3 and C = 4 in a flat array of 12 ints. What flat index is cell (2, 3)?
- A square matrix is symmetric when a[i][j] equals a[j][i]. What is the time needed to test an n x n matrix for symmetry in C?
- A singly linked list is built by inserting 1, 2, 3 at the head. Then two nodes are popped from the head and their values printed. What is…
- A circular singly linked list holds 1 -> 2 -> 3 -> back to 1. Starting at the head node, the program prints six consecutive values. What…
- A sorted list 1, 1, 2, 3, 3 has its duplicates removed by a loop that unlinks a node whose value equals the previous node's value. How…