Pointers & arrays formulas
Pointers, arrays and strings in C. 8 formulas for GATE CS Programming in C, each with when to use it. Each is explained in the topic notes.
IAE Academy: Pointers, arrays and strings in C formulas (GATE CS)
All 8 Pointers & arrays formulas
1-D ARRAY INDEXING / POINTER ARITHMETIC
For any array a with element type T. The same value is the address a + i. C arrays always start at index 0, and memory is byte-addressable.
2-D ROW-MAJOR ADDRESS (C ARRAYS)
The array is declared T a[R][C]. C is the number of COLUMNS (the row length), i is the row index and j is the column index, both starting at 0. The number of rows R does not appear.
3-D ROW-MAJOR ADDRESS
The array is declared T a[X][Y][Z], with all indices starting at 0. The first dimension X does not appear.
GENERAL ROW-MAJOR ADDRESS WITH ARBITRARY INDEX BOUNDS
Use this for a language-neutral array A[l1..u1][l2..u2] with element size w bytes, where Base is the address of A[l1][l2]. For column-major storage, swap the roles of the two indices: Base + ((j − l2)(u1 − l1 + 1) + (i − l1)) × w. For C arrays, l1 = l2 = 0 and this reduces to the formula above.
STORAGE FOR `CHAR T[] = "...";` (SIZE LEFT OUT)
n is the number of characters in the literal, which contains no embedded '\0'. The +1 is the terminator. So char t[] = "GATE"; gives sizeof(t) = 5 while strlen(t) = 4. If a size is written, the array has that size: char t[10] = "GATE"; has sizeof(t) = 10, with the unused bytes set to '\0'. char t[4] = "GATE"; is legal C but stores NO terminator.
MEMBER OFFSET (ALIGNMENT RULE)
Apply it member by member, in declaration order. 'End of previous member' is that member's offset plus its size, and it is 0 for the first member. align(m) is the alignment of m's type, equal to its size under the convention above.
STRUCT TOTAL SIZE (WITH TRAILING PADDING)
E is the end offset of the last member (its offset plus its size). A_max is the largest alignment among all members.
UNION SIZE
S_max is the size of the largest member and A_max is the largest alignment among all members.
Where this was asked: 2018 (1), 2020 (2), 2022 (2), 2024 (2), 2025 (3), 2026 (1). See the 11 previous-year questions on Pointers & arrays. This shows what was asked, not what will be asked.