incrementing a pointer to an array
- From: "subramanian100in@xxxxxxxxx, India" <subramanian100in@xxxxxxxxx>
- Date: Fri, 29 Aug 2008 23:29:22 -0700 (PDT)
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 ? Isn't it
similar to
int i_int = 100;
int *p = &i_int;
p++;
Here we cannot dereference 'p' but incrementing 'p' only once, is
allowed. Similarly,
ap is assigned '&a1'. Then we increment ap only once. Why is this
WRONG ?
Kindly clarify.
Thanks
V.Subramanian
.
- Follow-Ups:
- Re: incrementing a pointer to an array
- From: Martin Ambuhl
- Re: incrementing a pointer to an array
- From: Richard Tobin
- Re: incrementing a pointer to an array
- From: Richard Heathfield
- Re: incrementing a pointer to an array
- Prev by Date: Re: Problems With Global Variables (memory allocations)
- Next by Date: Re: incrementing a pointer to an array
- Previous by thread: Re: Questions about a Windows struct
- Next by thread: Re: incrementing a pointer to an array
- Index(es):