GATE | GATE-CS-2015 (Set 3) | Question 40
Consider the following two C code segments. Y and X are one and two dimensional arrays of size n and n × n respectively, where 2 ≤ n ≤ 10. Assume that in both code segments, elements of Y are initialized to 0 and each element X[i][j] of array X is initialized to i + j. Further assume that when stored in main memory all elements of X are in same main memory page frame.
Which of the following statements is/are correct?
S1: Final contents of array Y will be same in both code segments. S2: Elements of array X accessed inside the for loop shown in code segment 1 are contiguous in main memory. S3: Elements of array X accessed inside the for loop shown in code segment 2 are contiguous in main memory.
(A) Only S2 is correct
(B) Only S3 is correct
(C) Only S1 and S2 are correct
(D) Only S1 and S3 are correct
Explanation: In C, 2D arrays are stored in row major order. Therefore, S2 is correct, but S3 is not correct.
Quiz of this Question
My Personal Notes arrow_drop_up
Please Login to comment...