Re: incrementing a pointer to an array



subramanian100in@xxxxxxxxx, India said:

The following portion is from c-faq.com - comp.lang.c FAQ list ·
Question 6.13

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 ?

I'm not sure. I don't know of any reason why it's illegal. Maybe Steve just
means it's a lousy idea.

Isn't it
similar to
int i_int = 100;
int *p = &i_int;
p++;

Yes.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • Re: struct and function pointer in C
    ... subramanian100in@xxxxxxxxx, India said: ... It's useful in cases where you need to associate a function pointer with ... Richard Heathfield ... rjh at the above domain, ...
    (comp.lang.c)
  • Re: Excercise 5-9 (K&R II)
    ... mdh said: ... You stop incrementing it, ... Richard Heathfield ... rjh at the above domain, ...
    (comp.lang.c)