What is the output of the following C program?
[gamipress_button type=”submit” label=”Run Code Online” onclick=”window.open(‘https://coderseditor.com’,’_blank’)”]
#include<stdio.h> int main() { int i, j; int arr[4][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16} }; for(i = 0; i < 4; i++) for(j = 0; j < 4; j++) printf("%d ", j[i[arr]] ); printf("\n"); for(i = 0; i < 4; i++) for(j = 0; j < 4; j++) printf("%d ", i[j[arr]] ); return 0; }
Studently Answered question October 10, 2022
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
Use of pointer arithmetic is used to access array elements. Therefore, the meaning of j[i[arr]] and arr[i][j] is the same. Both of them denote (arr + 4*i + j). The meanings of arr[j][i] and i[j[arr]] are identical.
Studently Answered question October 10, 2022