edited by
36,170 views
100 votes
100 votes

For a C program accessing $\mathbf{X[i] [j] [k]}$, the following intermediate code is generated by a compiler. Assume that the size of an integer is $32$ bits and the size of a character is $8$ bits. 

t0 = i ∗ 1024 
t1 = j ∗ 32
t2 = k ∗ 4 
t3 = t1 + t0 
t4 = t3 + t2 
t5 = X[t4]

Which one of the following statements about the source code for the C program is CORRECT?

  1. $\mathbf{X}$ is declared as "int $\mathbf{X[32] [32] [8]}$.
  2. $\mathbf{X}$ is declared as "int $\mathbf{X[4] [1024] [32]}$.
  3. $\mathbf{X}$ is declared as "char $\mathbf{X[4] [32] [8]}$.
  4. $\mathbf{X}$ is declared as "char $\mathbf{X[32] [16] [2]}$.
edited by

9 Answers

0 votes
0 votes

A 3d array defined as a[2][2][2] means that there are 2 2d arrays each of dimension 2x2, i.e., both of them have 2 rows and 2 columns. 

Suppose the array given in the question is A[x][y][z]. This means that there are x 2d arrays each having y rows and z columns.

In the questions, the equations for finding A[i][j][k] can be re written in the form of y and z as follows if the array is assumed to be of type 'int':-

t0 = i ∗ 1024 = i * (y*z) * 4
t1 = j ∗ 32 = j * z * 4
t2 = k ∗ 4 = k * 4

So from the above equations we get,

z*4=32

=> z=8

and y*z*4=1024

=> y=32

So we know that dimensions are A[x][32][8]. Since we assumed int, so A is the answer since it is of this form.

If you assume array to be char then,

t0 = i ∗ 1024 = i * (y*z) * 1 

t1 = j ∗ 32 = j * z * 1 

t2 = k ∗ 4 = k * 4

So from the above equations we get,

z*1=32

=> z=32

and y*z*1=1024

=> y=32

So none of the char options,i.e, options B and C are of the form A[x][32][32]. So A has to be the answer.

Answer:

Related questions

44 votes
44 votes
7 answers
1
29 votes
29 votes
4 answers
4
go_editor asked Sep 28, 2014
9,254 views
Which one of the following is NOT performed during compilation?Dynamic memory allocationType checkingSymbol table managementInline expansion