GATE / CS ARCHIVE

GATE CSE 2015 SET 3 / QUESTION 50

GATE CSE 2015 Set 3 Q50

Programming in C · Arrays & Strings · Full GATE CSE 2015 Set 3 paper

GATE 2015 Set 3, Q50 2 marks · MCQ
Report issue

Arrays & Strings

Question 50, GATE 2015: Y is a one-dimensional array of size n and X a C two-dimensional n×n array, with 2≤n≤10. Each segment starts with Y[i]=0 and X[i][j]=i+j. All X elements lie in the same main-memory page frame. Segment 1: for(i=0;i<n;i++) Y[i]+=X[0][i]; Segment 2: for(i=0;i<n;i++) Y[i]+=X[i][0]; Assess S1: final Y contents are identical; S2: X elements accessed in segment 1 are contiguous in memory; S3: X elements accessed in segment 2 are contiguous. Options: (A) S2 only; (B) S3 only; (C) S1 and S2 only; (D) S1 and S3 only.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Both loops add i to initially zero Y[i], because X[0][i]=0+i and X[i][0]=i+0.

2. In C row-major storage, X[0][i] traverses consecutive elements, whereas X[i][0] advances by n elements for n≥2. Being in one page does not make those column elements adjacent. Thus S1, S2, C.

Original paper, page 71 · Answer key