Pointer to an array

int a[10];
int (*ptr)[10];

Here ptr is an pointer to an array of 10 integers.

ptr = &a;

Now ptr is pointing to array of 10 integers.

You need to parenthesis ptr in order to access elements of array as (*ptr)[i] cosider following example:

Sample code

#include<stdio.h>
int main(){
  int b[2] = {1, 2}; 
  int  i;
  int (*c)[2] = &b;
  for(i = 0; i < 2; i++){
     printf(" b[%d] = (*c)[%d] = %d\n", i, i, (*c)[i]);
  }
  return 1;
}

Output:

 b[0] = (*c)[0] = 1
 b[1] = (*c)[1] = 2

Array of pointers

int *ptr[10];

Here ptr[0],ptr[1]....ptr[9] are pointers and can be used to store address of a variable.

Example:

main()
{
   int a=10,b=20,c=30,d=40;
   int *ptr[4];
   ptr[0] = &a;
   ptr[1] = &b;
   ptr[2] = &c;
   ptr[3] = &d;
   printf("a = %d, b = %d, c = %d, d = %d\n",*ptr[0],*ptr[1],*ptr[2],*ptr[3]);
}

Output: a = 10, b = 20, c = 30, d = 40

Answer from Chinna on Stack Overflow
🌐
Reddit
reddit.com › r/c_programming › an array of pointers vs a pointer to an array
r/C_Programming on Reddit: An array of pointers vs a pointer to an array
February 1, 2021 -

I've been reading K&R and the syntax that differentiates an array of pointers vs a pointer to an array is confusing me. They say that

int *array[100];

is an array of 100 pointers to integers. On the other hand,

int (*array)[100];

is a pointer to an array of 100 integers.

Can someone elaborate on why this is the case?

It seems to me that it should be the other way around, since *(array[100]) reads like a pointer to an array with 100 elements, while (*array)[100] looks very much like it should be an array of 100 pointers.

What am I missing here?

Top answer
1 of 4
7
Declarations in C are written to match their usage. So if you write int *array[100], this means array has type such that *array[100] is of type int. (Ignoring, of course, that 100 is an invalid array index!) So to determine the type of array, we can use the operator precedence rules. Array indexing is higher precedence than dereferencing, so *array[100] means that we first get index into an array, and then dereference the object we get out, and that all should result in an int. This means that array is an array of pointers to int. (*array)[100] reverses this. Now, it says if we dereference array, and then index into whatever we get out as an array, we get an int. Thus, it's a pointer to an array of ints. Lots of people try to explain this in terms of the 'right-left rule' or the 'spiral rule' or whatever - I find these just make things harder. It's all operator precedence.
2 of 4
5
What you're missing is probably the worst feature of C, and possibly the worst feature of any language, which is its confusing, convoluted type syntax. It doesn't read left to right, or right to left, but inside out. To try and make sense of it, it was supposed to mirror actual usage in an expression: *array[i] # parsed as *(array[i]), index first # then deref, so an array of pointers (*array)[i] # deref first then index, so pointer to array However, here C throws another curve ball: because derefs, derefs with offsets, and array indexing are all really the same thing, then whatever the declaration of array, either of these will work with no error! Good luck...
Arrays in c using pointers Jan 27, 2023
r/learnprogramming
3y ago
Pointer arrays Jul 7, 2022
r/cpp_questions
4y ago
More results from reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › c language › difference-between-pointer-to-an-array-and-array-of-pointers
Difference between pointer to an array and array of pointers - GeeksforGeeks
July 11, 2025 - : "Array of pointers" is an array of the pointer variables. It is also known as pointer arrays. Syntax: ... We can make separate pointer variables which can point to the different values or we can make one integer array of pointers that can ...
Discussions

c - Pointer to an array and Array of pointers - Stack Overflow
As I am just a learner, I am confused about the above question. How is a pointer to an array different from array of pointers? Please explain it to me, as I will have to explain it to my teacher. T... More on stackoverflow.com
🌐 stackoverflow.com
C pointer to array/array of pointers disambiguation - Stack Overflow
The reason that the first one is ... allowed to wrap parentheses around declarators. P[N] is an array declarator. P(....) is a function declarator and *P is a pointer declarator. So everything in the following is the same as without any parentheses (except for the one of the functions' ... More on stackoverflow.com
🌐 stackoverflow.com
Confused about pointer pointers and array pointers
dont combine multi dimension arrays and pointers, ull get lost very quick as for ur actual question, someone smarter than me might answer More on reddit.com
🌐 r/C_Programming
11
2
October 20, 2023
C: How do I differentiate between an array of pointers and a pointer to an array? - Stack Overflow
My understanding of arr_of_ptr is that "dereferencing an element of arr_of_ptr results in an int" - therefore the elements of arr_of_ptr are pointers to integers. On the other hand, dereferencing ptr_to_arr results in an array that I can then nab integers from, hence ptr_to_arr points to an array. More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is a Pointer to an Array?
A pointer to an array, also known as an array pointer, is used for accessing the various components of any given array. It focuses on the 0th component of any given array and can be declared to point to a whole array rather than only a single array component.
🌐
testbook.com
testbook.com › home › key differences › difference between a pointer to an array and array of pointers | testbook.com
Difference Between a Pointer to an Array and Array of Pointers ...
Can you resize the allocated memory of a pointer?
Yes, you can easily resize the allocated memory of a pointer later at any given time.
🌐
testbook.com
testbook.com › home › key differences › difference between a pointer to an array and array of pointers | testbook.com
Difference Between a Pointer to an Array and Array of Pointers ...
🌐
Testbook
testbook.com › home › key differences › difference between a pointer to an array and array of pointers | testbook.com
Difference Between a Pointer to an Array and Array of Pointers | Testbook.com
It focuses on the 0th component of any given array and can be declared to point to a whole array rather than only a single array component. An Array of Pointers, also known as pointer arrays, refers to an array of various pointer variables.
🌐
Aticleworld
aticleworld.com › home › difference between pointer to an array and array of pointers
Difference between pointer to an array and array of pointers - Aticleworld
March 13, 2020 - I am assigning the address of the array and address of the first element to the pointers. Now in the last, I am displaying the stored address by the pointers before and after performing increment operation. So the output will be, p = 0x0061FF04, ptr = 0x0061FF04 p = 0x0061FF08, ptr = 0x0061FF18 · Because the base type of p is int while the base type of ptr is ‘an array of 5 integers’. We know that the pointer arithmetic is performed relative to the base size, so if we write ptr++, then the pointer ptr will be shifted forward by 20 bytes.
🌐
LinkedIn
linkedin.com › pulse › difference-between-pointer-array-pointers-c-gupta-
Difference between pointer to an array and array of pointers in C++:
September 19, 2023 - Syntax: Pointer to an array : int *ptr; Array of pointers : int *ptr[3]; Pointer to an array: Pointer to an array is also known as array pointer. We are using the pointer to access the components of the array.
🌐
BYJUS
byjus.com › gate › difference-between-pointer-to-an-array-and-array-of-pointers
Find the Difference Between Pointer to an Array and ...
March 29, 2023 - It refers to an array of various pointer variables, also called the pointer arrays. One can easily create separate pointer variables pointing towards different ranges of values.
Find elsewhere
🌐
IIES
iies.in › home › about iies › iies vision
Array of Pointers and Pointer to Array in C Explained.
May 15, 2026 - Understanding the difference between ... management and data handling. Arrays of pointers offer flexibility for dynamic data, while pointers to arrays improve performance with contiguous memory storage....
Price: $$$
Address: No 80, Ahad Pinnacle, Ground Floor, 5th Main, 2nd Cross, 5th Block, Koramangala Industrial Area, 560095, Bangalore
Top answer
1 of 6
4

Pointer to an array

int a[10];
int (*ptr)[10];

Here ptr is an pointer to an array of 10 integers.

ptr = &a;

Now ptr is pointing to array of 10 integers.

You need to parenthesis ptr in order to access elements of array as (*ptr)[i] cosider following example:

Sample code

#include<stdio.h>
int main(){
  int b[2] = {1, 2}; 
  int  i;
  int (*c)[2] = &b;
  for(i = 0; i < 2; i++){
     printf(" b[%d] = (*c)[%d] = %d\n", i, i, (*c)[i]);
  }
  return 1;
}

Output:

 b[0] = (*c)[0] = 1
 b[1] = (*c)[1] = 2

Array of pointers

int *ptr[10];

Here ptr[0],ptr[1]....ptr[9] are pointers and can be used to store address of a variable.

Example:

main()
{
   int a=10,b=20,c=30,d=40;
   int *ptr[4];
   ptr[0] = &a;
   ptr[1] = &b;
   ptr[2] = &c;
   ptr[3] = &d;
   printf("a = %d, b = %d, c = %d, d = %d\n",*ptr[0],*ptr[1],*ptr[2],*ptr[3]);
}

Output: a = 10, b = 20, c = 30, d = 40

2 of 6
3

Background

Think of pointers as just a separate data type. They have their own storage requirements -- such as their size -- they occupy 8 bytes on a x86_64 platform. This is the case of void pointers void*.

In those 8 bytes the information stored is the memory address of another piece of data.

The thing about pointers is that since they "point" to another piece of data, it's useful to know what type that data is too so you can correctly handle it (know its size, and structure).

In stead of having their own data type name such as pointer they compose their name based on the data type they refer to such as int* a pointer to an integer. If you want a plain pointer without type information attached to it you have the option of using void*.

So basically each pointer (to int, to char, to double) is just a void* (same size, same use) but the compiler knows the data being pointed to is of type int and allows you to handle it accordingly.

/**
 *  Create a new pointer to an unknown type.
 */
void* data;

/**
 *  Allocate some memory for it using malloc
 *  and tell your pointer to point to this new
 *  memory address (because malloc returns void*).
 *  I've allocated 8 bytes (char is one byte).
 */
data = malloc(sizeof(char)*8);

/**
 *  Use the pointer as a double by casting it
 *  and passing it to functions.
 */
double* p = (double* )data;
p = 20.5;
pow((double* )data, 2);

Pointer to array

If you have an array of values (let's say integers) somewhere in memory, a pointer to it is one variable containing its address.

You can access this array of values by first dereferencing the pointer and then operating some work on the array and its values.

/**
 *  Create an array containing integers.
 */
int array[30];
array[0] = 0;
array[1] = 1;
...
array[29] = 29;

/**
 *  Create a pointer to an array.
 */
int (*pointer)[30];

/**
 *  Tell the pointer where the data is.
 */
pointer = &array;

/**
 *  Access the data through the pointer.
 */
(*pointer)[1] = 999;

/**
 *  Print the data through the array.
 *  ...and notice the output.
 */
printf("%d", array[1]);

Array of pointers

If you have an array of pointers to values, the entire array of pointers is one variable and each pointer in the array refers to somewhere else in the memory where a value is located.

You can access this array and the pointers inside it without dereferencing it but in order to reach a certain value from it you will have to dereference one of the pointers inside the array.

/**
 *  Create an array containing pointers to integers.
 */
int *array_of_pointers[30];
array_of_pointers[0] = 0;
array_of_pointers[1] = 1;
...
array_of_pointers[29] = 29;
🌐
YouTube
youtube.com › watch
Difference between Pointer to an array and Array of pointers in c programming language with example - YouTube
Difference between Array of pointers and Pointer to an array in c programming.Array of pointers (int *array_of_ptr[5]) - Array of pointers which can store th...
Published: August 13, 2021
🌐
Oreate AI
oreateai.com › blog › pointer-to-an-array-vs-array-of-pointers-untangling-the-cc-conundrum › 72ad23502d36225235e7ea63db682f56
Pointer to an Array vs. Array of Pointers: Untangling the C/C++ Conundrum - Oreate AI Blog
February 24, 2026 - Instead of one tool pointing to a whole array, you have a collection of tools, where each tool is a pointer. Think of it as a toolbox, and each slot in the toolbox holds a different key, with each key opening a specific house (or memory location).
🌐
Quora
quora.com › What-is-the-difference-between-an-array-of-pointers-and-a-pointer-to-an-array-using-suitable-example
What is the difference between an array of pointers and a pointer to an array using suitable example? - Quora
Answer (1 of 2): Array of pointer means , we have an array and each element in that array is a pointer . For e.g. - *p[50].// This means we have an array with each element as a pointer. Pointer to an array means , we have an array and that array is pointed by a pointer for some functions . For e...
🌐
W3Schools
w3schools.com › c › c_pointers_arrays.php
C Pointers and Arrays
Well, in C, the name of an array, is actually a pointer to the first element of the array.
🌐
Quora
quora.com › What-is-the-difference-between-the-array-of-pointers-and-pointer-arrays
What is the difference between the array of pointers and pointer arrays? - Quora
Answer (1 of 5): I think by pointer arrays you mean pointer to an array. The difference between the two is: 1. Array of pointers is an array which consists of pointers. Each pointer in the array points to a memory address. For example, you can have an array of Pointers pointing to several strin...
🌐
Quora
quora.com › Is-there-any-difference-between-an-array-of-pointers-and-the-pointer-to-an-array-in-C
Is there any difference between an array of pointers and the pointer to an array in C? - Quora
Answer (1 of 7): So it seems clear that C programming 101 students have gotten to pointers week. Pointers 101 A pointer in C is a typed integer variable that contains an address. An address is an integer that maps to a memory cell. Pointers have the quality that adding or subtracting from them...
🌐
Quora
quora.com › What-is-the-difference-between-pointer-and-array
What is the difference between pointer and array? - Quora
If you create an array of size N, you have allocated storage for N elements. A pointer doesn’t allocate anything. It only holds an address or a null value (NULL or nullptr). OK, I suppose it could also hold garbage if you fail to initialize it properly, and it can also be abused to hold certain ...
Top answer
1 of 3
4

The main difference is that this is legal:

int **p1 = arr_of_ptr;

While this is not:

int **p2 = ptr_to_arr;

Because arr_of_ptr is an array, it can (in most contexts) decay to a pointer to its first element. So because the elements of arr_of_ptr are of type int *, a pointer to an element has type int ** so you can assign it to p1.

ptr_to_arr however is not an array but a pointer, so there's no decaying happening. You're attempting to assign an expression of type int (*)[x] to an expression of type int **. Those types are incompatible, and if you attempt to use p2 you won't get what you expect.

2 of 3
1

First,

I also have a rough understanding that arrays themselves are pointers, and that arr[p] evaluates to (arr + p * sizeof(data_type_of_arr)) where the name arr decays to the pointer to the first element of arr.

This isn't strictly correct. Arrays are not pointers. Under most circumstances, expressions of array type will be converted ("decay") to expressions of pointer type and the value of the expression will be the address of the first element of the array. That pointer value is computed as necessary and isn't stored anywhere.

Exceptions to the decay rule occur when the array expression is the operand of the sizeof, _Alignof, or unary & operators, or is a string literal used to initialize a character array in a declaration.

Having said all that, ptr_to_arr has pointer type, not array type - it will not "decay" to int **.

Given the declaration

T arr[N];

the following are true:

 Expression        Type            Decays to            Equivalent expression
 ----------        ----            ---------            ---------------------
        arr        T [N]           T *                  &arr[0]
       *arr        T               n/a                  arr[0]
     arr[i]        T               n/a                  n/a
       &arr        T (*)[N]        n/a                  n/a

The expressions arr, &arr[0], and &arr all yield the same value (modulo any differences in representation between types). arr and &arr[0] have the same type, "pointer to T" (T *), while &arr has type "pointer to N-element array of T" (T (*)[N]).

If you replace T with pointer type P *, such that the declaration is now

P *arr[N];

you get the following:

 Expression        Type            Decays to            Equivalent expression
 ----------        ----            ---------            ---------------------
        arr        P *[N]          P **                 &arr[0]
       *arr        P *             n/a                  arr[0]
     arr[i]        P *             n/a                  n/a
       &arr        P *(*)[N]       n/a                  n/a

So given your declarations, it would be more correct to write something like this:

int arr[x];
int *p1 = arr;         // the expression arr "decays" to int *

int *arr_of_ptr[x];
int **p2 = arr_of_ptr; // the expression arr_of_ptr "decays" to int **

/**
 * In the following declarations, the array expressions are operands
 * of the unary & operator, so the decay rule doesn't apply.
 */
int (*ptr_to_arr)[x] = &arr;
int *(*ptr_to_arr_of_ptr)[x] = &arr_of_ptr;

Again, ptr_to_arr and ptr_to_arr_of_ptr are pointers, not arrays, and do not decay to a different pointer type.

EDIT

From the comments:

Can I just hand-wavily explain it as: an array of pointers has a name that can decay to a pointer,

Yeah, -ish, just be aware that it is hand-wavey and not really accurate (which is shown by example below). If you are a first-year student, your institution isn't doing you any favors by making you deal with C this early. While it is the substrate upon which most of the modern computing ecosystem is built, it is an awful teaching language. Awful. Yes, it's a small language, but aspects of it are deeply unintuitive and confusing, and the interplay between arrays and pointers is one of those aspects.

an array of pointers has a name that can decay to a pointer, but a pointer to an array, even when dereferenced, does not give a give me something that decays to a pointer?

Actually...

If ptr_to_arr has type int (*)[x], then the expression *ptr_to_arr would have type int [x], which would decay to int *. The expression *ptr_to_arr_of_ptr would have type int *[x], which would decay to int **. This is why I keep using the term "expression of array type" when talking about the decay rule, rather than just the name of the array.

Something I have left out of my explanations until now - why do array expressions decay to pointers? What's the reason for this incredibly confusing behavior?

C didn't spring fully-formed from the brain of Dennis Ritchie - it was derived from an earlier language named B (which was derived from BCPL, which was derived from CPL, etc.)1. B was a "typeless" language, where data was simply a sequence of words or "cells". Memory was modeled as a linear array of "cells". When you declared an N-element array in B, such as

auto arr[N];

the compiler would set aside all the cells necessary for the array elements, plus an extra cell that would store the numerical offset (basically, a pointer) to the first element of the array, and that cell would be bound to the variable arr:

     +---+
arr: | +-+-----------+
     +---+           |
      ...            |
     +---+           |
     |   | arr[0] <--+
     +---+
     |   | arr[1]
     +---+
      ...
     +---+
     |   | arr[N-1]
     +---+
      

To index into the array, you'd offset i cells from the location stored in arr and dereference the result. IOW, a[i] was exactly equivalent to *(a + i).

When Ritchie was developing the C language, he wanted to keep B's array semantics (a[i] is still exactly equivalent to *(a + i)), but for various reasons he didn't want to store that pointer to the first element. So, he got rid of it entirely. Now, when you declare an array in C, such as

int arr[N];

the only storage set aside is for the array elements themselves:

+---+
|   | arr[0]
+---+
|   | arr[1]
+---+
 ... 
+---+ 
|   | arr[N-1]
+---+

There is no separate object arr which stores a pointer to the first element (which is part of why array expressions cannot be the target of an assignment - there's nothing to assign to). Instead, that pointer value is computed as necessary when you need to subscript into the array.

This same principal holds for multi-dimensional arrays as well. Assume the following:

int a[2][2] = { { 1, 2 }, { 3, 4 } };

What you get in memory is the following:

   Viewed as int             Viewed as int [2]
   +---+                     +---+
a: | 1 | a[0][0]           a:| 1 | a[0]
   +---+                     + - +
   | 2 | a[0][1]             | 2 |
   +---+                     +---+
   | 3 | a[1][0]             | 3 | a[1]
   +---+                     + - +
   | 4 | a[1][1]             | 4 |
   +---+                     +---+

On the left we view it as a sequence of int, while on the right we view it as a sequence of int [2].

Each a[i] has type int [2], which decays to int *. The expression a itself decays from type int [2][2] to int (*)[2] (not int **).

The expression a[i][j] is exactly equivalent to *(a[i] + j), which is equivalent to *( *(a + i) + j ).


  1. As detailed in The Development of the C Language
🌐
Spiceworks
community.spiceworks.com › programming & development
Difference Between Pointer to an Array and Array of Pointers - Programming & Development - Spiceworks Community
March 28, 2007 - Can anyone explain to me how the compiler differentiates the following: int *a[10] ; int (*a)[10]; Thanks