2.4k views

Consider the following declaration of a two-dimensional array in C:

char $a[100][100]$;

Assuming that the main memory is byte-addressable and that the array is stored starting from memory address $0$, the address of $a [40][50]$ is:

1. $4040$
2. $4050$
3. $5040$
4. $5050$
edited | 2.4k views

In C, arrays are always stored in row-major form.

Formula to evaluate 2-D array's location is:----

$loc(a[i][j]) = BA + [(i-lb_1)\times NC+(j-lb_2)]\times c$

Where,

$BA$ - Base Address
$NC$ - no. of columns
$c$ - memory size allocated to data type of array

$a[lb_1 \cdots ub_1] [lb_2\cdots ub_2]$

Here, $BA=0, NC =100, c=1, a[0.....99][0......99]$ so $lb_1=0 , lb_2=0$

$loc(a[40][50])= 0+ [ (40-0)\times 100 + (50-0)]\times 1$
$= 0+[4000+50]\times 1 = 4050$

edited
+2
Why column major used here,and not row major?
0
very well explained
0
i think by these ans may be contradict but by default we use  column majaor

.its a naive approach :)
0
why coloum major order plese explain because if we solve this from row major order then anwer will come out to be 5040 (Option C) which is also given in the option ?
0
Why element size is 1?
0
char --> 1
+7
Who is using column major? It is row-major which is mandated in C.
0

@Arjun sir....any source plss

+5
B is the answer, and RMO is used here not CMO.
0
Because here both answers are given, 1)CMO - 5040 , 2) RMO - 4050 then how to decide the correct one?
0

Shubhgupta Use row major .Use column major when it is exclusively mentioned in question.

0
Here it is used in row major order.
0
what are lb1 and lb2??
+1 vote

OPTION B

1
2