Arrays and pointers are closely linked in C: every subscript you have written so far was really a pointer operation. Understanding this link explains why arrays are passed to functions by address and makes pointer notation for arrays easy to read.
An array name as an address
In most expressions, the name of an array is automatically converted to a pointer to its first element. So for int arr[5];, the expression arr has the same value as &arr[0].
Subscript notation
Pointer notation
Meaning
&arr[0]
arr
Address of the first element
&arr[i]
arr + i
Address of element i
arr[0]
*arr
Value of the first element
arr[i]
*(arr + i)
Value of element i
The same holds for a pointer: after int *p = arr;, p[i] and *(p + i) both mean arr[i].
An array is not a pointer
Array int arr[5];
Pointer int *p = arr;
What it is
Five int objects
One variable holding an address
sizeof
20 (5 × 4 bytes)
8
Can be made to refer elsewhere
No: arr = ... and arr++ are errors
Yes: p = ..., p++
Elements can be assigned
Yes: arr[1] = 3;
Yes: p[1] = 3;
Pointers and two-dimensional arrays
A two-dimensional array is an array of rows. For int arr[3][3];:
Expression
Meaning
arr
Pointer to row 0
arr + i
Pointer to row i
*(arr + i) or arr[i]
Row i itself, which converts to a pointer to its first element
*(arr + i) + j
Address of element j in row i
*(*(arr + i) + j)
Value of arr[i][j]
Read *(*(arr + i) + j) from the inside out: go to row i, step to column j, take the value.
Key takeaways
In expressions, an array name becomes a pointer to its first element: arr equals &arr[0].
arr[i] is *(arr + i); &arr[i] is arr + i.
Arrays are not pointers: different sizeof, and an array name cannot be assigned.
arr[i][j] is *(*(arr + i) + j).
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Write a function sum(int *p, int n) that adds the elements of an array using pointer notation only (no square brackets), and show how it is called for int a[4] = {1, 2, 3, 4};.
Show worked answer
int sum(int *p, int n) { int i, total = 0; for (i = 0; i < n; i++) total = total + *(p + i); return total; }. Call: printf("%d\n", sum(a, 4));. The array name a is converted to the address of its first element, which is copied into p; *(p + i) is then the i-th element, so the function returns 1 + 2 + 3 + 4 = 10.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/pointers/arrays-and-pointers/ to read this page.