Skip to main content

Arrays and Pointers – Understanding Their Relationship

Updated 4 min readMarkdown
Part of seriesC Programming

In the last lesson, we learned:

  • What pointers are

  • How & gives an address

  • How * dereferences a pointer

Now we connect that knowledge to arrays.

This is the moment many students say:

“Ohhhh… so that’s what’s really happening.”

By the end of this lesson, you will understand:

  • Why array names behave like pointers

  • Why a[i] and *(a + i) mean the same thing

  • What pointer arithmetic is

  • The difference between arrays and pointers

1. The Most Important Idea

When you declare an array:

int a[5] = {10, 20, 30, 40, 50};

The name a represents:

The address of the first element.

So:

a == &a[0]

That is extremely important.

The array name behaves like a pointer to its first element.

2. Visualizing Memory

Suppose memory looks like this:

Address   Value
1000      10
1004      20
1008      30
1012      40
1016      50

If a stores address 1000, then:

a      → 1000
a + 1  → 1004
a + 2  → 1008

Each time you add 1, it moves by the size of an int.

That is pointer arithmetic.

3. Pointer Arithmetic

Let’s look at this code:

#include <stdio.h>

int main() {
    int a[3] = {10, 20, 30};

    printf("%d\n", *a);
    printf("%d\n", *(a + 1));
    printf("%d\n", *(a + 2));

    return 0;
}

Output:

10
20
30

Why?

Because:

*a       == a[0]
*(a+1)   == a[1]
*(a+2)   == a[2]

So this means:

a[i] == *(a + i)

They are equivalent.

4. Why This Works

When you write:

a[i]

C internally translates it to:

*(a + i)

So indexing is just pointer arithmetic combined with dereferencing.

This is not magic.

It is simple math with memory addresses.

5. Using a Pointer to Traverse an Array

You can also use a pointer variable:

#include <stdio.h>

int main() {
    int a[3] = {10, 20, 30};
    int *p = a;

    for (int i = 0; i < 3; i++) {
        printf("%d\n", *(p + i));
    }

    return 0;
}

Here:

  • p stores the address of a[0]

  • p + 1 moves to the next element

  • *(p + i) retrieves the value

6. Are Arrays and Pointers the Same?

They behave similarly.

But they are NOT the same.

Important differences:

1. Arrays have fixed size

int a[5];

You cannot change the size of a.

2. Array name cannot be reassigned

This is illegal:

a = some_other_address;   // Error

Array names are constant addresses.

3. Pointers can be reassigned

int x = 10;
int y = 20;

int *p = &x;
p = &y;   // Allowed

Pointers are flexible.

Arrays are fixed.

7. Why This Matters

Understanding arrays and pointers helps you:

  • Work with strings

  • Pass arrays to functions

  • Manage memory

  • Understand how C really works

If you skip this understanding, advanced topics will feel confusing.

8. Common Mistakes

❌ Confusing pointer arithmetic

When you write:

p + 1

It does NOT move by 1 byte.

It moves by:

sizeof(data_type)

If p is int*, it moves 4 bytes (usually).

❌ Forgetting array bounds

Even with pointer arithmetic, you must stay inside the array.

C will not protect you.

9. Practice Exercises

  1. Create an array of 4 integers and print them using:

    • indexing (a[i])

    • pointer arithmetic (*(a + i))

  2. Assign a pointer to an array and use it to modify elements.

  3. Draw memory layout for:

    int a[3] = {5, 6, 7};
    
  4. Explain why a[2] equals *(a + 2).

Final Thoughts

Today you learned something powerful:

  • Array names are addresses.

  • Indexing is pointer arithmetic.

  • a[i] is the same as *(a + i).

  • Arrays and pointers are related but not identical.

This understanding makes C much clearer.

In the next lesson, we will move to strings — which are just arrays of characters.

And everything you learned today will make that lesson easier.

About the author

  • Heya! 👋 I love helping people, and one of the best ways I do this is by sharing what I learn and build. I started as a pharmacist at a tertiary hospital in Northern Ghana, where I saw how much technology could improve healthcare. That sparked my interest in digital health. I taught myself to code, then joined the ALX Software Engineering program, which became a turning point. I went on to complete a Master of Health Informatics at the University of Toronto. Today I am a software and AI engineer and a health informatician, and I practise remotely as a Digital Health Pharmacist. I combine clinical experience with technical skills to build tools that solve real problems in health and beyond, and I write here about what I build and what I learn.

No comments yet. Be the first to comment.

C Programming

Part 21 of 40

From today, I will be starting lessons on C programming in my ALX Software Engineering class and I look forward to sharing with you everything I learn through this series.

Up nextStrings in C – Arrays of CharactersIn the previous lessons, you learned about: Arrays Pointers How arrays and pointers are related Now we will apply that knowledge to something very common in programming: strings. In C, strings ar

More from this blog