It's purely a type issue.

In most expression contexts the name of an array (such as var) decays to a pointer to the initial element of the array, not a pointer to the array. [Note that this doesn't imply that var is a pointer - it very much is not a pointer - it just behaves like a pointer to the first element of the array in most expressions.]

This means that in an expression var normally decays to a pointer to an int, not a pointer to an array of int.

As the operand of the address-of operator (&) is one context where this decay rule doesn't apply (the other one being as operand of the sizeof operator). In this case the type of &var is derived directly from the type of var so the type is pointer to array of 5 int.

Yes, the pointers have the same address value (the address of an arrays first element is the address of the array itself), but they have different types (int* vs int(*)[5]) so aren't compatible in the assignment.

ISO/IEC 9899:1999 6.3.2.1/4:

Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type "array of type" is converted to an expression of type "pointer to type" that points to the initial element of the array object and is not an lvalue. ...

Answer from Lara Bailey on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_pointer_to_an_array.htm
Pointer to an Array in C
In all the three cases, you get the same output − · Pointer 'ptr' points to the address: 647772240 Address of the first element: 647772240 Address of the first element: 647772240 · If you fetch the value stored at the address that ptr points to, that is *ptr, then it will return 1. It is legal to use array names as constant pointers and vice versa.
Discussions

Is it possible in C to assign pointer to an array or change to address of array to the pointer address? - Stack Overflow
Closed 4 years ago. I need to assign pointer returning function to an array, is it possible? More on stackoverflow.com
🌐 stackoverflow.com
Array Declaration and pointer assignment in C - Stack Overflow
I am confused in the basics of pointer and array declaration in C. I want to know the difference between following two statements except that base address to array is assigned to ptr in seconed sta... More on stackoverflow.com
🌐 stackoverflow.com
How should I assign a pointer to an array to a structure?
string is a pointer to char, not a pointer to array. This would have a pointer to an array in the struct and solve your problem. struct sample { char (*string)[8]; } However, I suspect that you do not want a pointer to an array here at all. :) Consider test.string = &arr[0] or test.string = arr; in order to get a pointer into the array instead of a pointer to the array. (In this case, keep the struct as is.) More on reddit.com
🌐 r/cprogramming
25
6
July 11, 2024
c - How can I assign an array to pointer? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Anyone know how can I solve that? I'm stucked on this for hours... ... You can't assign an array to a pointer. But you can assign a pointer to a pointer. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Wikibooks
en.wikibooks.org › wiki › C_Programming › Pointers_and_arrays
C Programming/Pointers and arrays - Wikibooks, open books for an open world
November 9, 2025 - Pointers and array names can pretty much be used interchangeably; however, there are exceptions. You cannot assign a new pointer value to an array name. The array name will always point to the first element of the array. In the function returnSameIfAnyEquals, you could however assign a new ...
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 76292-how-assign-value-pointer-pointers-array.html
How to assign value to the pointer in pointers to an array
February 26, 2006 - Not really, just the array name without the operator is fine because arrays automatically expose their address. I think you said this yourself in your first post .. hmm xeddiex. Sly is correct. It is a matter of type. ... char foo[10]; foo // yields a pointer to character - char* &foo // yields a pointer to a character array [10] - char (*) [10]; As Sly said, the second syntax is very rare.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › pointer-array-array-pointer
Pointer to an Array | Array Pointer - GeeksforGeeks
In the above program, we have a pointer ptr that points to the 0th element of the array. Similarly, we can also declare a pointer that can point to whole array instead of only one element of the array.
Published   April 30, 2025
Top answer
1 of 2
3

No, you cannot reassign an array as you do here:

int q[3];
q = *(int [3]) arrayReturn(z); 

If you want to copy the contents of z to q, you can do that with the memcpy library function:

memcpy( q, z, sizeof z );

but the = operator isn't defined to copy array contents.

Otherwise, the best you can do is declare q as a pointer and have it point to the first element of z:

int *q = z; // equivalent to &z[0]

Unless it is the operand of the sizeof or unary * operators, or is a string literal used to initialize a character array in a declaration, an expression of type "N-element array of T" will be converted, or "decay", to an expression of type "pointer to T" and the value of the expression will be the address of the first element of the array - that's why the above assignment works.

Arrays in C are simple sequences of elements - there's no metadata indicating their size or type, and there's no separate pointer to the first element. As declared, the arrays are

   +---+
z: | 1 | z[0]
   +---+
   | 2 | z[1]
   +---+
   | 3 | z[2]
   +---+
    ...
   +---+
q: | ? | q[0]
   +---+
   | ? | q[1]
   +---+
   | ? | q[2]
   +---+

There's no separate object q to assign to.

2 of 2
1

A pointer is a variable which contains an address of memory. Array is just a place in the memory that occupies so many bytes. As a result, they are very different objects and cannot be assigned to each other.

However, a pointer can be used to point to an array and as a result can be used in copying data from one array to another, for example, using memcpy.

int c[3];
memcpy(c, arrayReturn(z), sizeof(c));

Of course, there is no checking of array sizes done and it is assumed that the size of an array to which points the return of the arrayReturn() is big enough to be copied to c. Neither there is a way to find out about the size of the array which it points to.

Top answer
1 of 3
5

1. Bidimensional array:

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

With this statement in memory you have 2x3 integers, all adjacent in memory.I suppose that you know how to access them, but in the case you don't I'll clarify it:

a[0][0] : 1
a[0][1] : 2
a[0][2] : 3
a[1][0] : 4
a[1][1] : 5
a[1][2] : 6

2. Pointer to array:

int (*ptr)[3] = &a[0];

ptr points to a int[3] block of memory.So you can assign it only to an int[3] type:

ptr= &a[0];
ptr= &a[1];

The difference is that this pointer does not have it's own memory, and you have to assign it to an int[3] variable or allocate it:

ptr= malloc (2*sizeof(int[3]);

This way you can use the memory pointed by ptr, if you initialize ptr this way:

for(int j=0; j<2; j++)
    for(int i=0; i<3;i++)
        ptr[j][i]=i+j*3+1;

This case you'll have the same memory representation of int a[2][3], except that this memory is in the heap and not in the stack.You can always choose to realloc/free the memory and this memory is not deleted once your function terminates.

2 of 3
1

You should know operator precedence rules in C: http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedencehttp://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence

int (*ptr)[3] as opposed to int * ptr [3]

The first one is a pointer (notice * is closer to the var name) to arrays of int of size 3 The second one is equal to int (*(ptr [3])) which is an array of size 3 on int pointers.

You can also use this site: http://cdecl.org/ if you have doubts on how to interpret an expression.

Find elsewhere
🌐
HowStuffWorks
computer.howstuffworks.com › tech › computer software › programming
Using Pointers with Arrays - The Basics of C Programming | HowStuffWorks
March 8, 2023 - If you want to copy a into b, you have to enter something like the following instead: ... Better yet, use the memcpy utility in string.h. Arrays in C are unusual in that variables a and b are not, technically, arrays themselves. Instead they are permanent pointers to arrays.
🌐
Eskimo
eskimo.com › ~scs › cclass › notes › sx10e.html
10.5 ``Equivalence'' between Pointers and Arrays
The first such operation is that it is possible to (apparently) assign an array to a pointer: int a[10]; int *ip; ip = a; What can this mean? In that last assignment ip = a, aren't we mixing apples and oranges again? It turns out that we are not; C defines the result of this assignment to be ...
🌐
Denniskubes
denniskubes.com › 2012 › 08 › 19 › pointers-and-arrays-in-c
Basics of Pointers and Arrays in C – Dennis Kubes
Even though we can’t change the array variable directly, we can have a pointer to the array and then change that pointer. Here we create two arrays and two int pointers. We assign the numbers variable to ptr1 and numbers2 variable to ptr2. We then assign ptr2 to ptr1.
🌐
Usf
rc.usf.edu › tutorials › classes › tutorial › c_intro › chapter7.html
Research Computing - USF IT Documentation - Confluence
Research Computing, a department within Information Technology, has been established to promote the availability of high performance computing resources essential to effective research at the University of South Florida · Research computing consists of five broad and integrated areas of ...
🌐
Reddit
reddit.com › r/cprogramming › how should i assign a pointer to an array to a structure?
r/cprogramming on Reddit: How should I assign a pointer to an array to a structure?
July 11, 2024 -

I'm working on a project, and would like to assign a pointer to an array to a struct, which I've managed to do, but I keep getting a warning, here is an example:

struct sample {
  char *string;
}

int main() {
  char arr[8] = "Hello";
  struct sample test;
  test.string = &arr;
  hkprint(test.string);
}

This actually does work, but I compiling it produces the following warning warning: assignment to ‘char *’ from incompatible pointer type ‘char (*)[8]’ [-Wincompatible-pointer-types]

I try to do thing is as "solid" a way as possible, so I want to know if this is the proper way to do this, and I should just ignore the warning, or if there's a better way

I would also like to better understand why the warning is happening in the first place, since it seems to me that the types are the same, but the compiler clearly views them as incompatible

🌐
Linux Hint
linuxhint.com › create-use-array-pointers-c
Create and Use Array of Pointers in C – Linux Hint
Most of us are familiar with creating arrays with data types such as integers, characters, or floats. This guide will show you how to create an array of pointers and use it to store data.
🌐
Studytonight
studytonight.com › c › pointers-with-array.php
Pointer to Array in C Programming
September 17, 2024 - You cannot decrement a pointer once incremented. p-- won't work. Use a pointer to an array, and then use that pointer to access the array elements.