Consider the below code snippet:
int x[] ={10,20,30,40,50};
int *p;
int **q;
p = x; /* Obviously p now holds base address of array. So no problem here */
q = &x; /* Error. Why? */
I am getting this error in gcc compiler.
error: cannot convert ‘int (*)[5]’ to ‘int**’ in assignment q = &x;
An array variable can be considered as constant pointer to first element of the array. Then why cant I assign the address of the constant pointer i.e) &x to pointer of pointer variable q ?
&xis of typeint (*)[5], notint **— just like the error message says. They're quite different types, as you can see from the spelling. Trying to treat the value as an array of pointers would lead to horrible problems because it isn't an array of pointers.int []toint *, so what's the difference?&is the difference. What else do you think could be the cause of the trouble?