Re: incrementing a pointer to an array
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 30 Aug 2008 08:39:40 GMT
In article <2e8c4eff-4156-4352-8279-a75f0e952657@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
subramanian100in@xxxxxxxxx, India <subramanian100in@xxxxxxxxx> wrote:
int a1[3] = {0, 1, 2};
int a2[2][3] = {{3, 4, 5}, {6, 7, 8}};
int *ip; /* pointer to int */
int (*ap)[3]; /* pointer to array [3] of int */\
ap = &a1;
printf("%d\n", **ap);
ap++; /* WRONG */
Here why is incrementing ap ie 'ap++' mentioned as WRONG ?
Because the next line, which you have omitted, is
printf("%d\n", **ap); /* undefined */
The increment in isolation is not wrong, but if you're intending to
dereference the pointer, it is.
-- Richard
--
Please remember to mention me / in tapes you leave behind.
.
- References:
- incrementing a pointer to an array
- From: subramanian100in@xxxxxxxxx, India
- incrementing a pointer to an array
- Prev by Date: Re: incrementing a pointer to an array
- Next by Date: Re: incrementing a pointer to an array
- Previous by thread: Re: incrementing a pointer to an array
- Next by thread: Re: incrementing a pointer to an array
- Index(es):
Relevant Pages
|