Re: [links, FAQ] multidimensional arrays and pointers
- From: "Mike Wahler" <mkwahler@xxxxxxxxxxxx>
- Date: Tue, 31 May 2005 07:02:31 GMT
<junky_fellow@xxxxxxxxxxx> wrote in message
news:1117516970.445477.182870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Consider a 2-dimensional array,
> char arr[3][3] = { 'a','b','c',
> 'd','e','f',
> 'g','h','i'
> };
>
> what is the difference between,
>
> (arr + 1) and
> *(arr + 1)
The expression '(arr + 1)' yields the address
of the type 'char[3]' object (an array) whose
first element is located three bytes past the
starting address of the array 'arr'. The
expression's type is 'char(*)[3]' (pointer to
array of three characters).
*(arr + 1) yields the address of the type 'char'
object located three bytes past the starting address
of the array 'arr'. The expression's type is
'char *' (pointer to type 'char').
Thus, both expressions yield the same value (the
address of the character object with the value 'd'
in your example); however the two expressions' types
are different ('char(*)[3]' and 'char*', respectively.
(The actual address value of the two expressions will
vary among implementations, and often between different
executions of the program on the same platform)
I hope I didn't just do your classwork for you. :-)
(If I've erred in the above, someone will be sure to
point it out.) :-)
More info about arrays and pointers here:
http://web.torek.net/torek/c/pa.html
Other good information from Mr. Torek on C here:
http://web.torek.net/torek/c/
comp.lang.c FAQ here:
http://www.eskimo.com/~scs/C-faq/top.html
-Mike
.
- Follow-Ups:
- Re: multidimensional arrays and pointers
- From: claudius
- Re: multidimensional arrays and pointers
- References:
- multidimensional arrays and pointers
- From: junky_fellow
- multidimensional arrays and pointers
- Prev by Date: Re: multidimensional arrays and pointers
- Next by Date: Re: size of pointer variables
- Previous by thread: Re: multidimensional arrays and pointers
- Next by thread: Re: multidimensional arrays and pointers
- Index(es):
Relevant Pages
|