MCQ · 2 marks · Memory Hierarchy
GATE CS 2015 CS-3 — Q50
Consider the following two C code segments. and are one and two dimensional arrays of size and respectively, where . Assume that in both code segments, elements of are initialized to 0 and each element of array is initialized to . Further assume that when stored in main memory all elements of are in same main memory page frame.
Code segment 1:
Code segment 1:
//initialize elements of Y to 0
//initialize elements X[i][j] of X to i+j
for(i = 0; i < n; i++)
Y[i] += X[0][i];Code Segment 2:
//initialize elements of Y to 0
//initialize elements X[i][j] of X to i+j
for(i = 0; i < n; i++)
Y[i] += X[i][0];Which of the following statements is/are correct?
S1: Final contents of array will be same in both code segments
S2: Elements of array accessed inside the for loop shown in code segment 1 are contiguous in main memory
S3: Elements of array accessed inside the for loop shown in code segment 2 are contiguous in main memory
S1: Final contents of array will be same in both code segments
S2: Elements of array accessed inside the for loop shown in code segment 1 are contiguous in main memory
S3: Elements of array accessed inside the for loop shown in code segment 2 are contiguous in main memory