• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

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. C
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 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

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments