60 60 votes 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:$4040$$4050$$5040$$5050$ Programming in C gatecse-2002 programming-in-c programming array easy + – Kathleen 39.3k views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply Show 4 previous comments Kiyoshi commented Nov 16, 2021 reply Follow flag Thanks got it...😊 0 0 replyShare Shukla_ commented Jun 19, 2023 reply Follow flag &a[40][50]=&*(*(a+40)+50)=*(a+40)+50 &a is a pointer to complete 2D array. a is a pointer to first row of 2D array. *a is a pointer to first element of first row of 2D array. **a is the first element of 2D array. a+1 to 2nd row and so on…. So if starting address of array is 0 then a=0 a+1 points to next row so a+1=100 (100 char in each row) a+2=200…. a+40=4000 now *(a+40) points to first character of 41th row So *(a+40)+1=4001 *(a+40)+2=4002……. *(a+40)+50=4050. There is no need to remember any formula :) 21 21 replyShare S_Sandeep commented Sep 11 reply Follow flag NOTE: for 2D array, A[D1][D2] we want to know address of A[i][j] Address = BaseAddress + (Offset x Element size) Offset = (i x D2) + j 1 1 replyShare Please log in or register to add a comment.
Best answer 76 76 votes The answer is (B). In $\mathbb{C},$ arrays are always stored in the 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, $\text{BA}$ - Base Address $\text{NC}$ - no. of columns $c$ - memory size allocated to data type of array $a[lb_1 \ldots ub_1] [lb_2\ldots ub_2]$ Here, $\text{BA} = 0, \text{NC} = 100, c=1, a[0 \ldots 99][0\ldots 99]$, so $lb_1=0 , lb_2=0$ $loc(a[40][50])= 0+ [ (40-0)\times 100 + (50-0)]\times 1$ $\qquad \qquad \quad = 0+[4000+50]\times 1 = 4050$. Kalpna Bhargav answered Nov 30, 2014 • edited May 31, 2021 by Lakshman Bhaiya Kalpna Bhargav comment Share Follow See all 15 Comments 15 15 Comments reply Angkit commented Jun 13, 2017 reply Follow flag Why column major used here,and not row major? 2 2 replyShare akankshadewangan24 commented Jun 29, 2017 reply Follow flag very well explained 0 0 replyShare akankshadewangan24 commented Jun 29, 2017 reply Follow flag i think by these ans may be contradict but by default we use column majaor .its a naive approach :) 0 0 replyShare nikunj commented Sep 1, 2017 reply Follow flag 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 0 replyShare Simar sandhu commented Sep 3, 2017 reply Follow flag Why element size is 1? 0 0 replyShare Mk Utkarsh commented Oct 9, 2017 reply Follow flag char --> 1 0 0 replyShare Arjun commented Oct 9, 2017 reply Follow flag Who is using column major? It is row-major which is mandated in C. 21 21 replyShare shefali1 commented Nov 11, 2017 reply Follow flag @Arjun sir....any source plss 0 0 replyShare vishalshrm539 commented Nov 26, 2017 reply Follow flag B is the answer, and RMO is used here not CMO. 9 9 replyShare Shubhgupta commented Mar 25, 2018 reply Follow flag Because here both answers are given, 1)CMO - 5040 , 2) RMO - 4050 then how to decide the correct one? 0 0 replyShare Angkit commented Mar 30, 2018 reply Follow flag Shubhgupta Use row major .Use column major when it is exclusively mentioned in question. 3 3 replyShare Kv Kumar commented Oct 13, 2018 reply Follow flag Here it is used in row major order. 0 0 replyShare Pabitra Sahoo commented Jan 8, 2019 reply Follow flag what are lb1 and lb2?? 0 0 replyShare JashanArora commented Dec 28, 2019 reply Follow flag i think by these ans may be contradict but by default we use column majaor .its a naive approach :) Any newbie please note that this information is incorrect. Row Major Order is default in C (unrelated: Static scoping is also default in C) 3 3 replyShare koshta1999 commented Dec 11, 2021 reply Follow flag Small thing but very img , before that i though both are right 0 0 replyShare Please log in or register to add a comment.
46 46 votes $a$ $\underbrace{[100]}$ $\underbrace{[100]}$ $\text{Streets}$ $\text{Buildings}$ Now you want to go and meet a friend who lives on $50^{th}$ building of $40^{th}$ street means $a[40][50]$ So, firstly cross $39 (0-39)$ streets each consist of $100$ buildings: $40\times 100=4000$ Now cross $49(0-49)$ buildings in order to reach your destination: $50$ $Ans: 4050$ KUSHAGRA गुप्ता answered Dec 26, 2019 • edited Oct 10, 2020 by Lakshman Bhaiya KUSHAGRA गुप्ता comment Share Follow See all 4 Comments 4 4 Comments reply JashanArora commented Dec 28, 2019 reply Follow flag Good analogy! I always use "Skip i rows and j columns", thanks to you I'll add a story behind that from now on. Elaborating your answer for completeness' sake. Skip 40 rows and 50 columns => Skip 40*(Size of column) elements + 50 elements. => Skip 40*100 elements + 50 elements. => Skip 4050 elements. Here, the element is char, and 1 char takes up 1 Byte. So, 4050 Bytes. => 4050th address. Also, note that this approach works when the initial element is at A[0][0]. If somewhere else like A[-5][2], then skip accordingly. 7 7 replyShare meivinay commented Jan 9, 2021 reply Follow flag My man forgot about base address... And size of element, lower bound,But still not matter in this case 3 3 replyShare Rajsukh Mohanty commented Jan 19, 2024 reply Follow flag great ans! this shows that there is no need to memorize any formula to calculate. 0 0 replyShare Rajsukh Mohanty commented Jan 19, 2024 reply Follow flag great explanation! This shows that there is no need to memorize any formula to calculate. 0 0 replyShare Please log in or register to add a comment.
8 8 votes OPTION B abhishekmehta4u answered Mar 30, 2018 abhishekmehta4u comment Share Follow 0 reply Please log in or register to add a comment.
2 2 votes Address(a[i][j]) = Base + (i * COL + j) * sizeStep Tree:1. size = sizeof(datatype) --> here char = 12. COL = given second dimension (100)3. Substitute i=40, j=504. Address = (40*100 + 50)*1 + 0 = 4050So final = 4050 Gopi_Tirumala answered Aug 14, 2025 Gopi_Tirumala comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote Considering a 2D array: Tushar Rana answered Nov 29, 2025 Tushar Rana comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote METHOD-1METHOD-2We don't need to rely on formulas for everything. It's just simple aptitude.Answer: OPTION B Sudo_404_Div answered May 24 • edited Jul 13 by Sudo_404_Div Sudo_404_Div comment Share Follow 0 reply Please log in or register to add a comment.