For a C program accessing 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?This question was previously asked in

GATE CS 2014 Official Paper: Shift 2

- X is declared as “int X[32][32][8]”.
- X is declared as “int X[4][1024][32]”.
- X is declared as “char X[4][32][8]”.
- X is declared as “char X[32][16][2]”.

Option 1 : X is declared as “int X[32][32][8]”.

Free

IBPS SO IT Officer Mains: Full Mock Test

4812

60 Questions
60 Marks
45 Mins

**Explanation:**

t5 can be written as :

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

t5 = X[ i ∗ 1024 + j ∗ 32 + k ∗ 4]

Option 1: Suppose we want to calculate address of X[1][1][1]

- In order to reach X[1] we have to cross 32x8 integer each integer size is 4byte so t0 = i * 1024 (here i = 1 so t0 = 1024 ).
- Now we are at X[1] but we want to go to X[1][1]we have to cross 8 integer element size of each element is 4B so t1 = j*32 ( here j = 1 so t1=32 )
- Now we are at X[1][1] but we want to go to X[1][1][1] we have to cross 1 integer element size of each element is 4B so t2 = k*4 ( here k = 1 so t2 = 4 )

So option 1 is the correct answer.

India’s **#1 Learning** Platform

Start Complete Exam Preparation

Daily Live MasterClasses

Practice Question Bank

Mock Tests & Quizzes

Trusted by 2,16,91,267+ Students

Start your FREE coaching now >>

Testbook Edu Solutions Pvt. Ltd.

1st & 2nd Floor, Zion Building,

Plot No. 273, Sector 10, Kharghar,

Navi Mumbai - 410210

[email protected]
Plot No. 273, Sector 10, Kharghar,

Navi Mumbai - 410210

Toll Free:1800 833 0800

Office Hours: 10 AM to 7 PM (all 7 days)