PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम 2D Arrays: Row-Major Order (RMO) Address Calculation (2D एरे: रो-मेजर ऑर्डर (RMO) पता गणना और संख्यात्मक प्रश्न) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Row-Major Order (RMO) linearizes a 2D matrix into 1D RAM by storing every element of row 0 consecutively, followed by row 1, row 2, and so on—the native layout used by C, C++, Java, Pascal, and Python NumPy. Given base B, element width w, total columns N = UC - LC + 1, and lower bounds LR and LC, Loc(A[i][j]) equals B + w * [N * (i - LR) + (j - LC)].
अध्याय सार: रो-मेजर ऑर्डर (RMO) में 2D मैट्रिक्स को 1D मेमोरी में पंक्ति-दर-पंक्ति (Row-by-Row) संग्रहीत किया जाता है—पहले पूरी पहली पंक्ति और फिर दूसरी पंक्ति आती है; यही C, C++, Java, Pascal और Python NumPy का मानक है। यदि बेस B, तत्व चौड़ाई w, कुल कॉलम्स N = UC - LC + 1 और लोअर बाउंड्स LR, LC हों, तो A[i][j] का पता B + w * [N * (i - LR) + (j - LC)] होता है।
2D Arrays: Row-Major Order (RMO) Address Calculation: Detailed Notes & Architecture (2D एरे: रो-मेजर ऑर्डर (RMO) पता गणना और संख्यात्मक प्रश्न)
1. Row-by-Row Linearization Mechanism & Language Standards (पंक्ति-दर-पंक्ति रैखिकीकरण और भाषाओं के मानक)
[EN] Computer physical memory is a single one-dimensional sequence of byte addresses, so multidimensional arrays must be mapped onto 1D storage. In Row-Major Order, the rightmost index varies fastest: elements along a horizontal row (A[i][0], A[i][1], ..., A[i][N-1]) occupy adjacent bytes, and row i+1 starts immediately after row i ends. C, C++, Objective-C, Pascal, Java (conceptually per row array), and NumPy (C-order) default to RMO.
[HI] कंप्यूटर की मुख्य मेमोरी एकआयामी (1D) होती है, इसलिए 2D एरे को पंक्ति या कॉलम के क्रम में फैलाकर रखा जाता है। रो-मेजर ऑर्डर (RMO) में दाहिना (कॉलम) इंडेक्स सबसे तेजी से बदलता है: एक पंक्ति के सभी कॉलम लगातार रखे जाते हैं और उनके तुरंत बाद अगली पंक्ति शुरू होती है। C, C++, Pascal और Python NumPy डिफ़ॉल्ट रूप से RMO का उपयोग करते हैं।
2. Exact RMO Formulas: Zero-Based & Generalized Bounds (सटीक RMO सूत्र: 0-आधारित व सामान्य लोअर/अपर बाउंड्स)
[EN] For a zero-indexed C array A[R][C] where rows run 0..R-1 and columns run 0..C-1, skipping i full rows skips i * C elements, plus j elements in the current row: Loc(A[i][j]) = B + w * (i * C + j). With generalized lower and upper bounds A[LR..UR][LC..UC], first calculate total columns per row N = UC - LC + 1; then Loc(A[i][j]) = B + w * [N * (i - LR) + (j - LC)]. Notice that total row count M never appears in the RMO formula!
[HI] 0-आधारित C एरे A[R][C] में i पूरी पंक्तियाँ पार करने पर i * C तत्व और फिर j कॉलम आगे जाने पर पता B + w * (i * C + j) मिलता है। सामान्य बाउंड्स A[LR..UR][LC..UC] के लिए पहले एक पंक्ति में कुल कॉलम्स N = UC - LC + 1 निकालें, फिर सूत्र B + w * [N * (i - LR) + (j - LC)] लगाएं। ध्यान दें कि RMO सूत्र में कुल पंक्तियों M की आवश्यकता नहीं होती!
3. Step-by-Step Numerical Walkthrough & Stride Analysis (चरण-दर-चरण संख्यात्मक हल व स्ट्राइड (Stride) विश्लेषण)
[EN] To solve RMO problems error-free under exam time pressure: (1) identify N = UC - LC + 1 (columns per row), (2) compute completed rows (i - LR) and multiply by N, (3) add column offset (j - LC), and (4) multiply the total element offset by byte width w before adding Base B. Moving right by one column (A[i][j] to A[i][j+1]) increases the address by w bytes, while moving down one row (A[i][j] to A[i+1][j]) jumps by N * w bytes.
[HI] परीक्षा में बिना गलती हल करने के लिए: (1) कुल कॉलम N = UC - LC + 1 निकालें, (2) बीती हुई पंक्तियाँ (i - LR) को N से गुणा करें, (3) उसमें (j - LC) जोड़ें, और (4) प्राप्त कुल तत्वों को बाइट आकार w से गुणा कर बेस B में जोड़ें। एक ही पंक्ति में अगले कॉलम पर जाने से पता w बाइट्स बढ़ता है, जबकि अगली पंक्ति में उसी कॉलम पर जाने से पता N * w बाइट्स बढ़ता है।
4. CPU Cache Spatial Locality & C Function Parameter Rule (CPU कैश लोकैलिटी और C फंक्शन पैरामीटर का नियम)
[EN] Because adjacent columns in the same row sit side-by-side in RMO memory, iterating row-wise (outer loop i, inner loop j) accesses contiguous cache lines sequentially and achieves dramatically faster runtime than column-wise iteration (outer loop j, inner loop i) on large matrices. Furthermore, because the C compiler needs column count C to evaluate B + w * (i * C + j), any 2D array parameter in C MUST specify all dimensions except the first: void fn(int mat[][4], int rows).
[HI] RMO में एक ही पंक्ति के तत्व सटे रहने के कारण रो-वाइज लूप (बाहर i, अंदर j) चलाना कैश हिट बढ़ाकर कॉलम-वाइज लूप की तुलना में बहुत तेज प्रदर्शन देता है। साथ ही, C कंपाइलर को B + w * (i * C + j) निकालने के लिए कॉलम की संख्या C ज्ञात होना अनिवार्य है, इसलिए फंक्शन पैरामीटर में पहली पंक्ति संख्या छोड़ सकते हैं पर कॉलम संख्या लिखना जरूरी होता है (जैसे int mat[][4])।
Syntax, Formula & Technical Example (2D Arrays: Row-Major Order (RMO) Address Calculation)
// RMO Trace: int M[3][4] at Base = 5000, sizeof(int) = 4 bytes
// Memory order: M[0][0]..M[0][3] (5000..5012), M[1][0]..M[1][3] (5016..5028), M[2][0]..
// Find Loc(M[2][1]): N = 4 columns per row
// Element offset = 4 * (2 - 0) + (1 - 0) = 9 elements preceding M[2][1]
// Loc(M[2][1]) = 5000 + 4 * 9 = 5036
// C pointer form : *(*(M + 2) + 1) accesses address 5036
2D Arrays: Row-Major Order (RMO) Address Calculation Quick Reference & Comparison Table
| RMO Rule / Formula | Mathematical Expression | Exam Key Takeaway |
|---|---|---|
| Zero-Based RMO Formula | B + w * (i * C + j) | Depends on column count C; independent of row count R |
| General RMO Formula | B + w * [N * (i - LR) + (j - LC)] | N = UC - LC + 1 equals total columns per row |
| Vertical Row Stride | Loc(A[i+1][j]) - Loc(A[i][j]) = N * w | Jumping one row down skips N elements in RAM |
| Optimal Cache Traversal | Outer loop row i, inner loop column j | Sequential column reads maximize L1 cache hits |
2D Arrays: Row-Major Order (RMO) Address Calculation Top 20 Bilingual MCQs with Answers
Q1. How are elements of a 2D matrix physically arranged in Row-Major Order (RMO)?
(रो-मेजर ऑर्डर (RMO) में किसी 2D मैट्रिक्स के तत्व मेमोरी में किस क्रम में सहेजे जाते हैं?)
(A) Alternating one element from row 0 and one from column 0
(B) Only non-zero elements are stored in random heap blocks
(C) All elements of row 0 consecutively, followed by all elements of row 1, row 2, and so on
(D) All elements of column 0 consecutively, followed by column 1
Correct Answer: (C)
[EN] RMO stores each complete horizontal row sequentially in 1D RAM before moving to the next row.
[HI] RMO में पहले पूरी पंक्ति 0 के सभी तत्व लगातार सहेजे जाते हैं, उसके बाद पंक्ति 1 और फिर पंक्ति 2 आती है।
Q2. Which set of programming languages natively stores 2D arrays in Row-Major Order?
(निम्नलिखित में से किन भाषाओं का समूह डिफ़ॉल्ट रूप से 2D एरे को रो-मेजर ऑर्डर (RMO) में स्टोर करता है?)
(A) MATLAB and GNU Octave
(B) Fortran, MATLAB, and R
(C) C, C++, Pascal, and Python (NumPy default)
(D) Julia and Fortran only
Correct Answer: (C)
[EN] C, C++, Pascal, and Python NumPy default to Row-Major Order, whereas Fortran, MATLAB, R, and Julia use Column-Major Order.
[HI] C, C++, Pascal और Python (NumPy डिफ़ॉल्ट) रो-मेजर ऑर्डर अपनाते हैं, जबकि Fortran, MATLAB, R और Julia कॉलम-मेजर उपयोग करते हैं।
Q3. Given int A[10][15] in C (Base = 1000, w = 4 bytes), find the Row-Major address of A[4][6].
(C में घोषित int A[10][15] का बेस एड्रेस 1000 और तत्व आकार 4 बाइट्स है; RMO में A[4][6] का पता क्या होगा?)
(A) 1240
(B) 1256
(C) 1184
(D) 1264
Correct Answer: (D)
[EN] 0-based RMO: B + w * (i * C + j) = 1000 + 4 * (4 * 15 + 6) = 1000 + 4 * 66 = 1264.
[HI] सूत्र 1000 + 4 * (4 * 15 + 6) = 1000 + 4 * 66 = 1264 होगा।
Q4. An array A[1..10, 1..20] uses Row-Major Order with Base = 2000 and w = 2 bytes. Calculate Loc(A[5][12]).
(रो-मेजर एरे A[1..10, 1..20] में बेस एड्रेस 2000 और तत्व आकार 2 बाइट्स है; A[5][12] का पता निकालें।)
(A) 2202
(B) 2182
(C) 2228
(D) 2184
Correct Answer: (B)
[EN] N = 20 - 1 + 1 = 20 columns. Loc = 2000 + 2 * [20 * (5 - 1) + (12 - 1)] = 2000 + 2 * (80 + 11) = 2182.
[HI] कुल कॉलम N = 20 हैं। पता = 2000 + 2 * [20 * (5 - 1) + (12 - 1)] = 2000 + 2 * 91 = 2182।
Q5. Given 2D array A[-3..4, -2..5] in RMO with Base = 500 and w = 4 bytes, what is Loc(A[1][2])?
(RMO एरे A[-3..4, -2..5] का बेस एड्रेस 500 और w = 4 बाइट्स है; A[1][2] का पता क्या होगा?)
(A) 644
(B) 640
(C) 612
(D) 628
Correct Answer: (A)
[EN] N = 5 - (-2) + 1 = 8 columns. Row offset = 1 - (-3) = 4, Col offset = 2 - (-2) = 4. Loc = 500 + 4 * (8 * 4 + 4) = 500 + 144 = 644.
[HI] N = 5 - (-2) + 1 = 8 कॉलम। पंक्ति दूरी = 4 व कॉलम दूरी = 4। अतः 500 + 4 * (8*4 + 4) = 644।
Q6. In Row-Major Order for A[0..5, 0..9] with w = 4 bytes, if Loc(A[2][3]) = 4092, find the Base Address.
(यदि RMO में A[0..5, 0..9] (w = 4 बाइट्स) के तत्व A[2][3] का पता 4092 है, तो बेस एड्रेस क्या होगा?)
(A) 4000
(B) 4004
(C) 4012
(D) 3992
Correct Answer: (A)
[EN] N = 10 columns. Offset = 4 * (2 * 10 + 3) = 92 bytes. Thus Base = 4092 - 92 = 4000.
[HI] कुल कॉलम N = 10; ऑफसेट = 4 * (2 * 10 + 3) = 92 बाइट्स। अतः बेस = 4092 - 92 = 4000।
Q7. In an M x N matrix stored in Row-Major Order (element width w), what is the byte distance between A[i][j] and A[i+1][j]?
(M x N आकार के रो-मेजर मैट्रिक्स में A[i][j] और A[i+1][j] के बीच कितने बाइट्स का अंतर होता है?)
(A) (M + N) * w bytes
(B) N * w bytes
(C) w bytes
(D) M * w bytes
Correct Answer: (B)
[EN] Moving vertically down one row in the same column skips an entire row of N elements, totaling N * w bytes.
[HI] एक ही कॉलम में अगली पंक्ति पर जाने पर पूरी एक पंक्ति के N तत्व पार करने पड़ते हैं, अर्थात N * w बाइट्स।
Q8. In an RMO matrix, how many bytes separate A[i][j] and A[i][j+1]?
(रो-मेजर ऑर्डर में एक ही पंक्ति के दो पड़ोसी तत्वों A[i][j] और A[i][j+1] के बीच पते का अंतर कितना होता है?)
(A) N * w bytes
(B) 2 * w bytes
(C) M * w bytes
(D) w bytes (the size of one element)
Correct Answer: (D)
[EN] Consecutive columns within the same row are stored adjacent to each other in RMO, separated by exactly one element width w.
[HI] RMO में एक ही पंक्ति के क्रमागत कॉलम बिल्कुल सटे रहते हैं, इसलिए अंतर केवल एक तत्व की चौड़ाई w बाइट्स होता है।
Q9. Why must a C function parameter like void process(int a[][5], int r) explicitly specify the column dimension 5?
(C फंक्शन पैरामीटर void process(int a[][5], int r) में कॉलम संख्या 5 लिखना अनिवार्य क्यों होता है?)
(A) Because C forbids matrices having more than 5 columns
(B) Because RMO address calculation B + w * (i * C + j) requires column count C to determine row stride
(C) Because C stores 2D arrays in Column-Major Order
(D) Because row count r is computed by dividing 5
Correct Answer: (B)
[EN] Without knowing C (number of columns per row), the compiler cannot know how many bytes a[i] advances from a[0].
[HI] रो-मेजर सूत्र में पंक्ति आगे बढ़ाने (i * C) के लिए कॉलम्स की संख्या C जानना कंपाइलर के लिए अनिवार्य है।
Q10. Which pointer expression accesses A[i][j] in a statically declared 2D C array int A[4][5]?
(C में घोषित int A[4][5] के लिए इनमें से कौन सा पॉइंटर रूप A[i][j] के बिल्कुल समतुल्य है?)
(A) *(A[j] + i)
(B) **(A + i * j)
(C) *(A + i + j)
(D) *(*(A + i) + j)
Correct Answer: (D)
[EN] (A + i) points to row i; *(A + i) decays to &A[i][0]; adding j and dereferencing yields A[i][j].
[HI] (A + i) i-वीं पंक्ति दर्शाता है, *(A + i) उस पंक्ति के पहले तत्व का पता देता है, और +j करके * लगाने पर A[i][j] मिलता है।
Q11. In Row-Major Order, how many elements appear strictly before A[i][j] in A[LR..UR, LC..UC] (where N = UC - LC + 1)?
(RMO में A[LR..UR, LC..UC] (जहाँ N = UC - LC + 1) के अंदर A[i][j] से ठीक पहले कुल कितने तत्व होते हैं?)
(A) N * (i - LR) + (j - LC)
(B) M * (j - LC) + (i - LR)
(C) N * (i - LR + 1) + (j - LC)
(D) (i - LR) * (j - LC)
Correct Answer: (A)
[EN] There are (i - LR) complete preceding rows of N elements plus (j - LC) preceding elements inside row i.
[HI] वर्तमान पंक्ति से पहले (i - LR) पूरी पंक्तियाँ (प्रत्येक में N तत्व) और वर्तमान पंक्ति में (j - LC) तत्व होते हैं।
Q12. For a large 4096 x 4096 int matrix in C, why does summing by rows run significantly faster than summing by columns?
(C में बड़े 4096 x 4096 मैट्रिक्स का योग कॉलम-वाइज के बजाय रो-वाइज करने पर बहुत तेज क्यों चलता है?)
(A) Column-wise iteration uses floating-point division internally
(B) Row-wise loops skip bounds checking while column-wise loops enable it
(C) C stores rows on the Stack and columns on disk
(D) Row-wise iteration accesses contiguous RAM addresses sequentially, maximizing CPU cache hits
Correct Answer: (D)
[EN] Jumping by N * w bytes per inner step in column-wise loops causes frequent L1/L2 cache misses (thrashing).
[HI] रो-वाइज लूप लगातार सटी मेमोरी पढ़ता है जिससे CPU कैश हिट बढ़ते हैं, जबकि कॉलम-वाइज लूप हर बार बड़ा जंप लेकर कैश मिस कराता है।
Q13. What does the C code snippet output: int a[2][3] = {{1,2,3},{4,5,6}}; printf("%d", *(*(a + 1) + 2));?
(C कोड int a[2][3] = {{1,2,3},{4,5,6}}; printf("%d", *(*(a + 1) + 2)); का आउटपुट क्या होगा?)
(A) 5
(B) 4
(C) 6
(D) 3
Correct Answer: (C)
[EN] *(*(a + 1) + 2) equals a[1][2], which is row 1 (second row), column 2 (third element) = 6.
[HI] *(*(a + 1) + 2) का अर्थ a[1][2] है, अर्थात दूसरी पंक्ति का तीसरा तत्व = 6।
Q14. Which parameter is completely UNNECESSARY when computing Loc(A[i][j]) in Row-Major Order?
(रो-मेजर ऑर्डर में A[i][j] का पता निकालने के लिए इनमें से किस मान की आवश्यकता बिल्कुल नहीं होती?)
(A) Element byte width w
(B) Total number of columns N
(C) Total number of rows M (or upper row bound UR)
(D) Base address B
Correct Answer: (C)
[EN] The RMO formula B + w * [N * (i - LR) + (j - LC)] requires LR, LC, UC (for N), B, and w—never UR or total rows M.
[HI] RMO सूत्र में कुल पंक्तियों की संख्या M या ऊपरी पंक्ति सीमा UR की कभी आवश्यकता नहीं पड़ती।
Q15. If A[0..3][0..4] is stored in RMO with Base = 100 and w = 2 bytes, what is the address of the last element A[3][4]?
(यदि A[0..3][0..4] (w = 2 बाइट्स) RMO में बेस 100 पर है, तो अंतिम तत्व A[3][4] का पता क्या होगा?)
(A) 130
(B) 136
(C) 138
(D) 140
Correct Answer: (C)
[EN] 4 rows x 5 columns = 20 elements. A[3][4] is at 100 + 2 * (3 * 5 + 4) = 100 + 38 = 138.
[HI] 4 पंक्तियाँ व 5 कॉलम (N = 5) हैं; A[3][4] का पता = 100 + 2 * (3 * 5 + 4) = 138।
Q16. Which statement is NOT true about Row-Major Order (RMO)?
(रो-मेजर ऑर्डर (RMO) के संबंध में इनमें से कौन सा कथन असत्य (NOT true) है?)
(A) General RMO address formula uses total columns N = UC - LC + 1
(B) In RMO, elements within the same column (A[0][j], A[1][j], A[2][j]) sit in contiguous memory bytes
(C) A[i][j] immediately precedes A[i][j+1] in physical memory
(D) C and C++ natively store 2D arrays in Row-Major Order
Correct Answer: (B)
[EN] Elements in the same column are separated by N * w bytes in RMO; storing column neighbors contiguously is Column-Major Order (CMO).
[HI] एक ही कॉलम के तत्वों का लगातार मेमोरी में होना कॉलम-मेजर (CMO) की विशेषता है, रो-मेजर (RMO) की नहीं।
Q17. Within 2D Arrays: Row-Major Order (RMO) Address Calculation, which rmo rule / formula directly maps to: "B + w * (i * C + j)"?
(2D Arrays: Row-Major Order (RMO) Address Calculation में कौन सा RMO Rule / Formula सीधे "B + w * (i * C + j)" से संबंधित है?)
(A) General RMO Formula
(B) Optimal Cache Traversal
(C) Vertical Row Stride
(D) Zero-Based RMO Formula
Correct Answer: (D)
[EN] In 2D Arrays: Row-Major Order (RMO) Address Calculation, 'Zero-Based RMO Formula' handles 'B + w * (i * C + j)' (Depends on column count C; independent of row count R).
[HI] 2D Arrays: Row-Major Order (RMO) Address Calculation में 'Zero-Based RMO Formula' का कार्य/विवरण 'B + w * (i * C + j)' (Depends on column count C; independent of row count R) है।
Q18. Which option accurately describes 'General RMO Formula' in 2D Arrays: Row-Major Order (RMO) Address Calculation?
(2D Arrays: Row-Major Order (RMO) Address Calculation के संदर्भ में 'General RMO Formula' की सही विशेषता कौन सी है?)
(A) B + w * [N * (i - LR) + (j - LC)]
(B) Outer loop row i, inner loop column j
(C) B + w * (i * C + j)
(D) Loc(A[i+1][j]) - Loc(A[i][j]) = N * w
Correct Answer: (A)
[EN] 'General RMO Formula' provides 'B + w * [N * (i - LR) + (j - LC)]' — key point: N = UC - LC + 1 equals total columns per row.
[HI] 'General RMO Formula' का मुख्य विवरण 'B + w * [N * (i - LR) + (j - LC)]' है (N = UC - LC + 1 equals total columns per row)।
Q19. In 2D Arrays: Row-Major Order (RMO) Address Calculation, identify the correct parameter for the specification: "Loc(A[i+1][j]) - Loc(A[i][j]) = N * w".
(2D Arrays: Row-Major Order (RMO) Address Calculation में "Loc(A[i+1][j]) - Loc(A[i][j]) = N * w" विवरण किस विकल्प के लिए सही है?)
(A) Vertical Row Stride
(B) Optimal Cache Traversal
(C) General RMO Formula
(D) Zero-Based RMO Formula
Correct Answer: (A)
[EN] 'Vertical Row Stride' corresponds to 'Loc(A[i+1][j]) - Loc(A[i][j]) = N * w' (Jumping one row down skips N elements in RAM).
[HI] 'Vertical Row Stride' का संबंध 'Loc(A[i+1][j]) - Loc(A[i][j]) = N * w' (Jumping one row down skips N elements in RAM) से है।
Q20. Considering 2D Arrays: Row-Major Order (RMO) Address Calculation, what key behavior defines 'Optimal Cache Traversal'?
(2D Arrays: Row-Major Order (RMO) Address Calculation में 'Optimal Cache Traversal' की मुख्य भूमिका या मान क्या है?)
(A) Loc(A[i+1][j]) - Loc(A[i][j]) = N * w
(B) B + w * [N * (i - LR) + (j - LC)]
(C) Outer loop row i, inner loop column j
(D) B + w * (i * C + j)
Correct Answer: (C)
[EN] 'Optimal Cache Traversal' represents 'Outer loop row i, inner loop column j' (Sequential column reads maximize L1 cache hits).
[HI] 'Optimal Cache Traversal' का अर्थ/मान 'Outer loop row i, inner loop column j' है (Sequential column reads maximize L1 cache hits)।
2D Arrays: Row-Major Order (RMO) Address Calculation — Exam FAQs
Q1: Does the Row-Major Order address formula depend on the total number of rows M?
क्या रो-मेजर ऑर्डर (RMO) के सूत्र में कुल पंक्तियों (Rows) की संख्या M का उपयोग होता है?
[EN] No. Since rows fill completely from top to bottom, reaching row i only requires multiplying (i - LR) by the row width N (total columns per row); total rows M is unused.
[HI] नहीं। किसी पंक्ति i तक पहुँचने के लिए केवल यह जानना जरूरी होता है कि प्रत्येक पंक्ति में कितने कॉलम (N) हैं, न कि कुल कितनी पंक्तियाँ हैं।
Q2: Why does C require specifying the column size in int mat[][4] when passing a 2D array to a function?
फंक्शन में 2D एरे पास करते समय C में कॉलम का आकार int mat[][4] लिखना क्यों जरूरी है?
[EN] Without the column count (4), the compiler cannot compute the byte stride (4 * sizeof(int)) needed to advance from mat[i] to mat[i+1] under Row-Major layout.
[HI] कॉलम की संख्या जाने बिना कंपाइलर यह तय नहीं कर सकता कि अगली पंक्ति mat[i+1] कितने बाइट्स आगे शुरू होगी।
Q3: Is a dynamically allocated int **arr in C guaranteed to be contiguous Row-Major memory?
क्या C में int **arr द्वारा डायनामिक तरीके से बनाए गए 2D एरे भी एक ही निरंतर रो-मेजर ब्लॉक में होते हैं?
[EN] No! If each row is allocated via separate malloc() calls inside a loop, rows sit at different heap locations (jagged array), unlike a single contiguous flat block or int (*p)[COLS].
[HI] नहीं। यदि हर पंक्ति के लिए अलग से malloc() चलाया जाए तो पंक्तियाँ हीप में अलग-अलग स्थानों पर होंगी; पूर्णतः निरंतर मेमोरी के लिए सिंगल फ्लैटेड ब्लॉक या int (*p)[COLS] उपयोग करना होता है।
Post a Comment
Post a Comment