Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2015 Set 3
Questions

Q30

MCQ2 marks, −0.67Medium

Consider the following two C code segments. YY and XX are one and two dimensional arrays of size nn and n×n n \times n respectively, where 2≤n≤102 \leq n \leq 10. Assume that in both code segments, elements of YY are initialized to 00 and each element X[i][j]X[i][j] of array XX is initialized to i+ji+j. Further assume that when stored in main memory all elements of XX are in same main memory page frame. Code segment 1:1:

// initialize elements of Y to 0
// initialize elements of X[i][j] of X to i+j
for (i=0; i<n; i++)
    Y[i] += X[0][i];

Code segment 2:2:

// initialize elements of Y to 0
// initialize elements of 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 YY will be same in both code segments S2: Elements of array XX accessed inside the for loop shown in code segment 11 are contiguous in main memory S3: Elements of array XX accessed inside the for loop shown in code segment 22 are contiguous in main memory

Sign in to save attempts.

The solution is hidden while you attempt this question. It opens once you check or show the answer.