Re: incrementing a pointer to an array



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.
.



Relevant Pages

  • Re: Toss decision
    ... stated that he was intending that India do a late charge. ... His batting was the only thing positive about the Indian batting the ... Tendulkar was for India in the 90s. ...
    (rec.sport.cricket)
  • Re: how to check whether the page is the last page?
    ... I want to write code to do it by the php program itself rather than I ... As soon as number + X doesn't exists, you know the previous increment was your last page. ... Instead you should have that information stored in a database, but the DB structure depends totally on what you're intending to do. ...
    (comp.lang.php)
  • Help in Selecting University for Msc Control (UK)
    ... I am apsiring to do my Msc Control Engg and got offers from Univ of ... years experience in Automotive Control(in INDIA) and intending to ... pursue career in same field. ...
    (sci.engr.mech)
  • Help in Selecting University for Msc Control (UK)
    ... I am apsiring to do my Msc Control Engg and got offers from Univ of ... years experience in Automotive Control(in INDIA) and intending to ... pursue career in same field. ...
    (sci.engr.mech)
  • Help in Selecting University for Msc Control (UK)
    ... I am apsiring to do my Msc Control Engg and got offers from Univ of ... years experience in Automotive Control(in INDIA) and intending to ... pursue career in same field. ...
    (sci.engr.control)