I expected that using the & operator on an array of int in C would be assignable to int** as it works to assign an array of int (without the &) to an int*.The int is arbitrary here.
I saw this other question but it does not mention trying to assign & of an array of int to int** but to int*.. Assign address of address of array to pointer in C
For example..
#include <stdio.h>
int main()
{
int** a;
int b[5];
b[1] = 123;
//a = &b; //< results in output of warning "assignment to ‘int **’ from incompatible pointer type ‘int (*)[5]’"
int* c = b;
a = &c; //< this works
printf("*a is %i\n", (*a)[1]);
return 0;
}
From what I've read elsewhere &b above is a pointer to an array of int thus int(*)[].
It's not clear to me from the following either, because it would fall under the "Except" part because "it is the operand of [...] the unary & operator".
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.
The above is from ISO/IEC 9899:1999 6.3.2.1/4: according to.. https://stackoverflow.com/a/3504570
EDIT: though people have answered "it isn't possible" I still have not seen an explanation as to why this isn't a feature of C. Is there any case where it would cause a problem to allow the above? I don't see how it would make sense even if considering for example calling free(*a) as you could also call free(c). A reminder here that I do not appreciate "you should do it this way" answers. Commandeering really poisons stackoverflow i.m.o.. Let people try to figure out what works for them. If all you have is a "moral reason why you shouldn't" you don't have a reason at all.
int** ais a pointer to a pointer to an int. When you dereferenceathat location does not contain a pointer&bisint (*)[5]which is quite different fromint **.&operator on an array ofintin C would be assignable toint**as it works to assign an array ofint(without the&) to anint*." By that reasoning, you would need an array ofint *so that you could assign it (without the&) to anint **(which indeed you could).&returns the address of something. You can only return the address of something in memory because only things in memory have addresses. We call those things objects, and they include variables. So while using an array (int []) can degenerate into a pointer value (int *), you can't get the address of that pointer value anymore than you could get the address of42.