The Gateway to Computer Science Excellence
0 votes
Assuming pages of size 128 words each and array is stored in row major, how many page faults will be generated in the following C program?

int A[128][128];

for(int j=0;j<128;j++)

for(int i=0;i<128;i++)






in Operating System by Active (3.9k points) | 193 views
Is it B? Assuming size of an element=size of one word
@ mini panda yes it would be B as for every element we need new page so page fault would be 128*128=16384....if i would have been first loop than size thing must have created problem but here in this qsn its okk
Yes right. And since size is not mentioned so for the convenience i assumed it=4B
@mini panda even if you take 2 bytes answer wont change..:)
But how? Then each page will contain 256 array elements right? That is 2 rows(128*2). Then the answer would get halved right?
look when you have each element of size 2 bytes than as array is store row wise in one page you will have 64 elements i.e a[0][0].....a[0][64] we are accessing a[0][0] first ..................than a[1][0] so that will be stored in 3rd page i.e a[1][0]...a[1][64] so you need to bring new page in that will cause page fault............ now siilalrly for every i value you will need page fault ...

MiNiPanda and @ Shubham Shukla 6

consider word size is = size of int, otherwise you can get many answer


how can you say how many page faults without giving how many frames are allocated?

if no.of frames allocated =128 ====> it produce 128 page faults only

if no.of frames allocated < 128 ====> it produce 1282 page faults only


@shaik masthan 1 word by default=1 byte in size..

Shubham Shukla 6, who says it?

@shaikmasthan here page size= 128 byte

now whether int element take 2 bytes or 4 bytes in abve qsn  our page fault would be 128*128 only

But what if i would have been outer loop and j would have been inner loop than page fault would have been different and that would have dpend on integr size taken

if it would have been 2 than 1 page could have 64 elements so than page fault would have been 2*128 as for every i value you will get max 2 page fault

if size would have been 4 bytes than 1 page would have contained 32 elements than page fault would have been 4* for every i value page fault would have been 4.
@ shaikmasthan in CO you must have studied

Whatever be the size of int but it has to be equal to word size for this Q to get 214 as answer.

And by default word size is taken as 4B(or 2B sometimes) and not 1B as far as i know after studying CO..


Shubham Shukla 6 , 

for generalizing those two implementations, i considered as word size is = size of int

not only for implementation given in this question...

i know what you said....  and more over how people arguing take int size=4 Bytes by default, like that people arguing that word = 4 Bytes...

@shaikmasthan when nothing said in CO qsns and they talk about 1 word what you take while solving??
@minipanda any refernce where 1 word=4byte or 2bytes.???
not that here is a controversy with size of int, therefore you can't assume by default...


in your case, there is no controversy.... therefore you can assume by default as your wish..
@minipanda any qsn of gate where 1 word=2bytes or 4bytes..(until and unless mentioned)..???

This is from

Computer Organization
Book by Safwat G. Zaky, V. Carl Hamacher, and Zvonko Vranesic
In gate you can't guess anything by yourself untill it is mentioned ...and in gate they will surely mention the mapping...

so i thing any answer according to the guessing will  correct in this senario
@sushant yadav so what should we consider  here they have mentioned nothing about word size what according to you must be default size of word..?
I always take it as 1 byte whenever not given ..but it differs for different people..

1 Answer

+1 vote
Best answer
The answer seems to be $none\space of\space these$ to me, but trying to reach one of the other options by taking some assumptions.

Given that $128$ x $128$ words are stored in $row\space major$ order, ie; elements are stored row by row. so there are total $128$ pages, each page containing elements $A[i][0]$ to $A[i][127]$. [Word addressible memory is taken because the size of a word and integer are not given in bytes.]

Now in the loop of the program, the words are accessed in $column\space major$ order $\rightarrow A[0][0]$, $A[1][0]$, $A[2][0]$.. (inner loop is $i$).

Therefore a new page has to be accessed each time $A[i][j]$ is accessed.[Another assumption here, number of pages in memory at a time $<= 128$]
Hence the total number of page faults $= 128 * 128 = 16384$
So, the answer is $(B)$
by Active (1.5k points)
selected by

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,373 answers
105,289 users