---
title: "Relation between array and pointer"
subject: "Computer Programming"
chapter: 9
key: "semester_1/computer_programming:array-pointer-relation"
source: https://www.bctengineer.com/q/semester_1/computer_programming/array-pointer-relation
site: BCT Engineering
---

# Relation between array and pointer

Computer Programming · Chapter 9: Pointers

- Asked in: 2069 Asar, 3 marks; 2070 Chaitra, 5 marks; 2071 Chaitra, 4 marks; 2070 Asar, 3 marks; 2069 Chaitra, 3 marks (asked 5 times)
- Video: [#24 C Pointers and Arrays | C Programming For Beginners](https://www.youtube.com/watch?v=LscgaBzlGdE) — Programiz
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/array-pointer-relation
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-9

## Question

How are array and pointer related? Compare array and pointer with example. (Illustrate with example that "array is indirectly a pointer".)

## Answer

#### Relation between array and pointer
In C, the name of an array is the address of its first element (a constant pointer). If `int a[4]` and `int *p = a;`, then `p` holds `&a[0]`. Because of this:

- `a[i]` is exactly the same as `*(a + i)`, and `p[i]` is the same as `*(p + i)`.
- `a + i` is the address of the i-th element. Adding 1 to a pointer moves it by `sizeof` the element type (4 bytes for `int`).
- Arrays are passed to functions as pointers, so the function can change the original data.

So an array is "indirectly a pointer", and pointer arithmetic is used to walk through it.

```c
#include <stdio.h>

int main(void)
{
    int a[4] = {10, 20, 30, 40};
    int *p = a;                       /* same as &a[0] */

    for (int i = 0; i < 4; i++)
        printf("a[%d]=%d  *(a+%d)=%d  p[%d]=%d  *(p+%d)=%d\n",
               i, a[i], i, *(a + i), i, p[i], i, *(p + i));

    printf("sizeof(a) = %zu, sizeof(p) = %zu\n", sizeof a, sizeof p);
    return 0;
}
```

Output:

```text
a[0]=10  *(a+0)=10  p[0]=10  *(p+0)=10
a[1]=20  *(a+1)=20  p[1]=20  *(p+1)=20
a[2]=30  *(a+2)=30  p[2]=30  *(p+2)=30
a[3]=40  *(a+3)=40  p[3]=40  *(p+3)=40
sizeof(a) = 16, sizeof(p) = 8
```

#### Comparison

| Basis | Array | Pointer |
|---|---|---|
| Meaning | Block of same-type elements | Variable holding an address |
| Memory | Fixed size set at declaration | Only the address is stored (8 bytes here); data stored elsewhere |
| Assignment | Name cannot be changed (`a = a + 1` is an error) | Can point to other places (`p++`) |
| `sizeof` | Whole array (16 bytes above) | Size of the pointer (8 bytes here) |
| Allocation | Allocated automatically | Can use `malloc()` to get memory at run time |

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. If int a[4] and int *p = a;, which expression is exactly the same as a[2]?
   A. *(a) + 2
   B. *(p + 2)
   C. &a[2]
   D. *(p) * 2
   Answer: B. a[i] is defined as *(a + i), and p holds the address of a[0], so *(p + 2) is the same element. (Key point: a[i] equals *(a+i))

2. On a system where int is 4 bytes, what does adding 1 to an int pointer do?
   A. Moves the address by 1 byte
   B. Moves the address by 4 bytes
   C. Adds 1 to the value stored
   D. Moves the address by 8 bytes
   Answer: B. Adding 1 to a pointer moves it by sizeof the element type, here 4 bytes, to reach the next element. (Key point: Pointer arithmetic scaling)

3. Which statement about the array name a and a pointer p = a is correct?
   A. Both a = a + 1 and p++ are valid
   B. p++ is valid but a = a + 1 is an error
   C. a = a + 1 is valid but p++ is an error
   D. Neither can be changed
   Answer: B. The array name is a constant address and cannot be reassigned, while a pointer variable can be moved to other places. (Key point: Array name is constant)

4. For int a[4] and int *p = a on a 64-bit system, what do sizeof(a) and sizeof(p) give?
   A. 16 and 8
   B. 4 and 4
   C. 16 and 16
   D. 8 and 16
   Answer: A. sizeof(a) is the whole array (4 x 4 = 16 bytes) while sizeof(p) is only the size of a pointer (8 bytes). (Key point: sizeof array vs pointer)

## Related in Computer Programming

- [Reverse array and display via pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-reverse-array) — Computer Programming, chapter 9
- [Accessing array elements using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-access-array-elements) — Computer Programming, chapter 9
- [Copy string converting lower to upper using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-array-elements-copy-string-upper) — Computer Programming, chapter 9, asked 3×
- [Second largest element using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-second-largest) — Computer Programming, chapter 9
- [Pointers in pass by reference; 2D array](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-passing-by-reference-2d) — Computer Programming, chapter 9

## Related in other subjects

- [Pattern lobes and 180° out-of-phase array](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Alobes-importance-opposite-phase-array) — Propagation and Antenna, chapter 2
- [Two-element array: broadside and end fire](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Atwo-element-array-broadside-endfire) — Propagation and Antenna, chapter 2
- [Two-element array and end fire pattern](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Atwo-isotropic-endfire-pattern) — Propagation and Antenna, chapter 2
- [Flywheel energy relation and rim sizing](https://www.bctengineer.com/question.md?key=semester_7%2Ftheory_of_mechanism_and_machine_ii%3Aflywheel-energy-fluctuation-derivation) — Theory of Mechanism and Machine II, chapter 2
