Arrays and Pointers in C Formula Sheet: Address Rules and Revision Notes

Revise C arrays and pointers through compact identities, exact address traces, operator parsing, decay traps, and a practical retrieval routine.

KnowledgeGate Team

Exam prep & CS education

Updated 12 Nov 20266 min read
Arrays and Pointers in C Formula Sheet: Address Rules and Revision Notes

Array notation and pointer notation often produce the same numerical address, which makes revision deceptive. Their types, strides and legal operations are still different, so a familiar-looking expression can hide an invalid step. Use CS Fundamentals as the broader subject route. The key retrieval rules are one-dimensional and two-dimensional address formulas, pointer precedence, and boundary checks; rebuild them from the traces instead of memorising isolated symbols.

1. Arrays in C: the five identities worth memorising

Start with:

c
int a[5] = {7, 11, 13, 17, 19};
  • N = sizeof a / sizeof a[0], with valid indices 0 through N-1. Use it only on a complete array.

  • a[i] = *(a + i) and &a[i] = a + i. Use these when syntax mixes subscripting, addresses and dereferencing.

  • For a pointer p into the array, p[i] = *(p + i). Use it to expand pointer subscripting before tracing.

In most expressions, a converts to a pointer to its first element. It stays an array under sizeof and unary &. The name is not a modifiable lvalue, so a++ and a = p are invalid. The earlier Arrays and Pointers in C: Memory, Arithmetic, Traps owns the first-pass memory model, 2D derivation and precedence walkthrough; this sheet keeps the compact identities and revision checks.

2. Pointer arithmetic in C: scale by the pointed-to type

The teaching formula is address(p + k) = address(p) + k * sizeof(*p). Use it when converting an element offset into a byte address.

If p = &a[i], then p + k = &a[i+k] within the same array or at its one-past position. You may form and compare one-past, but never dereference it. Apply this bound rule before reading an address.

If q = &a[j] and p = &a[i] share an array, q - p = j - i. Use subtraction to count elements, not bytes; the result is ptrdiff_t. Unrelated arrays define no such distance.

An int * advances by one int, while an int (*)[5] advances by one complete five-int row. Parse the pointed-to type before tracing an offset.

3. Arrays and pointers worked example: one base address, eight results

Assume the invented model sizeof(int) = 4 bytes and base B = 1000. Round addresses make scaling visible. The earlier Relationship Between Arrays and Pointers in C owns the conceptual type distinction and its single-base memory strip; this sheet uses a separate five-value trace to make the formulas and operator checks retrievable.

c
int a[5] = {7, 11, 13, 17, 19};
int *p = &a[1];
int *q = &a[4];

Result

Step-by-step calculation

Array size

sizeof a = 5 * 4 = 20 bytes

Element count

sizeof a / sizeof a[0] = 20 / 4 = 5

a + 3

1000 + 3 * 4 = 1012

*(a + 3)

Address 1012 stores 17

p

&a[1] = 1000 + 1 * 4 = 1004

p + 2

1004 + 2 * 4 = 1012, value 17

q - p

(1016 - 1004) / 4 = 3 elements

a + 5

1000 + 5 * 4 = 1020, one-past, do not dereference

Use it to keep the base consistent. a + 5 is int *; &a + 1 is int (*)[5]. Both equal 1020 here, with strides 4 and 20 bytes. Equal addresses do not erase types.

Five-cell C array memory map showing values 7, 11, 13, 17, 19 at addresses 1000-1016, pointer positions, and one-past address 1020.

4. Two-dimensional arrays in C: row-major formula and address trace

Take int m[3][4] = {{2,4,6,8}, {10,12,14,16}, {18,20,22,24}};. Assume base B = 2000, sizeof(int) = 4, rows R = 3 and columns C = 4.

For valid zero-based indices, &m[i][j] = B + (i * C + j) * sizeof(int). Use this formula to flatten a row-major position into its element offset. Therefore:

&m[2][1] = 2000 + (2 * 4 + 1) * 4 = 2000 + 36 = 2036, and m[2][1] = 20.

Now trace the types. m converts to int (*)[4]. Thus m + 2 reaches row 2 at 2000 + 2 * 16 = 2032. Then *(m + 2) converts to an int * at 2032; adding 1 reaches 2036. Hence m[2][1] = *(*(m + 2) + 1) = 20. Use this expansion when a 2D subscript is mixed with pointer notation.

In void f(int m[][4]), the parameter adjusts to int (*m)[4]. The trailing dimension remains because the compiler needs the four-column row stride.

Three-by-four C matrix at base address 2000 with row-major addresses, highlighting m[2][1] = 20 at address 2036.

5. Pointer expressions in C: parse four operators before tracing them

Reset this fresh state before each independent case:

c
int a[5] = {7, 11, 13, 17, 19};
int *p = &a[1];
int x;

Expression

Parenthesised form

x

p after

Array change

x = *p++

x = *(p++)

11

&a[2]

None

x = (*p)++

x = ((*p)++)

11

&a[1]

a[1] becomes 12

x = *++p

x = *(++p)

13

&a[2]

None

x = ++*p

x = ++(*p)

12

&a[1]

a[1] becomes 12

Parenthesise postfix and prefix operators first, then separate pointer movement from pointee modification. In *p++, postfix ++ moves the pointer after reading its old pointee. In (*p)++ and ++*p, the pointer stays fixed while the pointee changes. Never infer a result from visual proximity.

6. Arrays and pointers traps: decay, declarations, bounds and lifetime

In a separate 64-bit model, sizeof(int *) = 8 and sizeof(int) = 4. void f(int a[5]) adjusts to int *a; inside, sizeof a / sizeof a[0] = 8 / 4 = 2, not caller length 5. The earlier Arrays and Strings in C: Decay, sizeof and 2D Addresses owns string sentinels, sizeof comparisons and the full row-major derivation; this sheet keeps the compact decay formula beside its declaration and lifetime traps.

Read from the identifier outwards. int *ap[5] is an array of five pointers to int. int (*pa)[5] = &a is one pointer to an array of five int; under the earlier model, pa + 1 advances 20 bytes.

Trap

Result

Correction

Dereference a + 5

Out of bounds

Never dereference one-past

Subtract unrelated pointers

No valid distance

Use one array only

Dereference null, uninitialised or dangling pointers

Invalid access

Point to a live object

Modify through const char *s = "GATE"

String-literal modification

Use char s[] = "GATE"

Assign one array to another

Invalid whole-array assignment

Copy elements explicitly

7. GATE arrays and pointers questions: a 90-second solving method

Common practice-question forms ask you to compute an element address, distinguish an array from a pointer or pointer-to-array, expand a subscript, trace pre-increment and post-increment, calculate a row-major address, check a bound, or identify an invalid dereference or lifetime error.

Use this six-step routine:

  1. Write every exact type.

  2. Mark whether array-to-pointer conversion occurs.

  3. Record base B, element size w, row width and valid bounds.

  4. Expand x[i] to *(x + i).

  5. Parenthesise ++, -- and * before tracing state.

  6. Reject a one-past dereference, unrelated-pointer subtraction, null access or dangling access before calculating output.

KnowledgeGate's C Programming > Arrays & Pointers question bank provides practice depth; it is not evidence of exam weightage, frequency or any official pattern. The scheduled Arrays and Pointers in C: 7 GATE Mistakes That Cost Marks owns the seven error-first corrections; this sheet stays with formulas, derivations and a compact operator table.

8. Arrays and pointers revision notes: the short version and next step

  • Subscripting is pointer addition followed by dereference.

  • Pointer arithmetic scales by the pointed-to type.

  • Pointer subtraction counts elements within one array.

  • A one-past pointer may be formed, but not dereferenced.

  • sizeof sees a real array only before parameter adjustment.

  • A 2D array decays to a pointer to its first row.

In ten minutes, rebuild the five-cell map from 1000. Recover 1012, 1020 and q - p = 3, then recompute m[2][1] at 2036 unseen. For broader study, continue with the C Language course.