Re: array pointer
Glynn Clements <[email protected]> Tue, 18 Jan 2011 19:33:31 +0000
| Newsgroups | org.kernel.vger.linux-c-programming |
|---|---|
| Message-ID | <[email protected]> |
ratheesh k wrote:
> int *s_ptr;
> int **d_ptr;
> int arr[2][2]={1,2,3,4};
>
> s_ptr=*arr; /* This is perfectly fine */
> d_ptr=arr /* this line throws a warning: assignment from incompatible
> pointer type */ ????????
Arrays are not pointers. If you use the name of an array as an
expression, it is treated as a pointer to the first element.
For one-dimensional arrays, this means that you can use an array in
most places where a pointer is required. But this doesn't hold for
higher dimensions; an array of pointers isn't the same as an array of
arrays. It also doesn't hold for many other cases, i.e. sizeof,
variable declarations, etc.
--
Glynn Clements <[email protected]>