Array name as pointers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • newgoat

    Array name as pointers

    As far as I understand, in "int arr[10]", the name of the integer array
    "arr"
    is equivalent to the pointer to the first element of the array. But is
    "arr"
    really a pointer, identical as "int *arr;" ?

    I tried to modify this "arr" thing in the following code. GCC warns
    me of incompatible pointers, which I have no idea of.

    ---------------------------------------------------------------
    #include<stdio. h>

    void incrementPtr(in t **);

    int main(int argc, char *argv[]){
    int i;
    int a[3] = {10, 20, 30};

    incrementPtr(&a );

    for(i = 0; i < 3; i++){
    printf("a[%d] = %d\n", i, *(a + i));
    }

    return 0;
    }

    void incrementPtr(in t **a){
    *a++;
    }
    -------------------------------------------------

    Anyone has any opinion why I got the warning? And
    if "a" in this code can be modified?

    Thanks.

  • Martin Ambuhl

    #2
    Re: Array name as pointers

    newgoat wrote:[color=blue]
    > As far as I understand, in "int arr[10]", the name of the integer array
    > "arr"
    > is equivalent to the pointer to the first element of the array. But is
    > "arr"
    > really a pointer, identical as "int *arr;" ?[/color]

    No. This question is so dead and boring it makes the parrot look
    lively. Do you imagine you are the first with this thought? It is to
    avoid repeatedly answering such things that we have a FAQ
    <http://c-faq.com/>. Please check it before posting.
    Among others, you might find interesting:

    <http://c-faq.com/aryptr/aryptr2.html> But I heard that char a[] was
    identical to char *a.

    <http://c-faq.com/aryptr/aryptrequiv.htm l> So what is meant by the
    ``equivalence of pointers and arrays'' in C?

    <http://c-faq.com/aryptr/aryptrparam.htm l> If they're so different, then
    why are array and pointer declarations interchangeable as function
    formal parameters?

    [...][color=blue]
    > Anyone has any opinion why I got the warning? And
    > if "a" in this code can be modified?[/color]

    Once you check the FAQ, as you should have already done, you will know
    the answer.

    Comment

    • Rod Pemberton

      #3
      Re: Array name as pointers


      "Martin Ambuhl" <mambuhl@earthl ink.net> wrote in message
      news:NfrVf.1028 5$sL2.5154@news read2.news.atl. earthlink.net.. .[color=blue]
      > newgoat wrote:[color=green]
      > > As far as I understand, in "int arr[10]", the name of the integer array
      > > "arr"
      > > is equivalent to the pointer to the first element of the array. But is
      > > "arr"
      > > really a pointer, identical as "int *arr;" ?[/color]
      >
      > No.[/color]

      Fair statement.
      [color=blue]
      > This question is so dead and boring it makes the parrot look
      > lively.[/color]

      ? I admit I'm asleep right now, but WTF did you forget?
      [color=blue]
      > Do you imagine you are the first with this thought?[/color]

      Hostility.
      [color=blue]
      > It is to
      > avoid repeatedly answering such things that we have a FAQ
      > <http://c-faq.com/>. Please check it before posting.
      > Among others, you might find interesting:
      >
      > <http://c-faq.com/aryptr/aryptr2.html> But I heard that char a[] was
      > identical to char *a.
      >
      > <http://c-faq.com/aryptr/aryptrequiv.htm l> So what is meant by the
      > ``equivalence of pointers and arrays'' in C?
      >
      > <http://c-faq.com/aryptr/aryptrparam.htm l> If they're so different, then
      > why are array and pointer declarations interchangeable as function
      > formal parameters?
      >[/color]

      Fair. Fair. Fair and Fair.
      [color=blue]
      > [...][color=green]
      > > Anyone has any opinion why I got the warning? And
      > > if "a" in this code can be modified?[/color]
      >
      > Once you check the FAQ ... you will know
      > the answer.
      >[/color]

      Fair.
      [color=blue]
      > Once you check the FAQ, as you should have already done,[/color]

      How could he know about the FAQ before you told him? Is he prescient? I
      thought that was only for God. And, I think it violates a number of laws of
      communication theory too.


      Rod Pemberton


      Comment

      • Skarmander

        #4
        Re: Array name as pointers

        Rod Pemberton wrote:[color=blue]
        > "Martin Ambuhl" <mambuhl@earthl ink.net> wrote in message
        > news:NfrVf.1028 5$sL2.5154@news read2.news.atl. earthlink.net.. .[color=green]
        >> newgoat wrote:[color=darkred]
        >>> As far as I understand, in "int arr[10]", the name of the integer array
        >>> "arr"
        >>> is equivalent to the pointer to the first element of the array. But is
        >>> "arr"
        >>> really a pointer, identical as "int *arr;" ?[/color]
        >> No.[/color]
        >
        > Fair statement.
        >[color=green]
        >> This question is so dead and boring it makes the parrot look
        >> lively.[/color]
        >
        > ? I admit I'm asleep right now, but WTF did you forget?
        >[/color]
        He is assuming a shared cultural heritage of geek, where everybody knows
        Monty Python's dead parrot sketch. It should come as no surprise that
        Wikipedia has a full article on it: http://en.wikipedia.org/wiki/Dead_Parrot.

        I must say I've seen kinder wordings of "read the FAQ".

        S.

        Comment

        • Richard G. Riley

          #5
          Re: Array name as pointers

          On 2006-03-26, Martin Ambuhl <mambuhl@earthl ink.net> wrote:[color=blue]
          > newgoat wrote:[color=green]
          >> As far as I understand, in "int arr[10]", the name of the integer array
          >> "arr"
          >> is equivalent to the pointer to the first element of the array. But is
          >> "arr"
          >> really a pointer, identical as "int *arr;" ?[/color]
          >
          > No. This question is so dead and boring it makes the parrot look
          > lively. Do you imagine you are the first with this thought? It is to
          > avoid repeatedly answering such things that we have a FAQ
          ><http://c-faq.com/>. Please check it before posting.[/color]

          I assume you will be as rude to everyone else in this NG whose
          questions are already answered in the FAQ and the Ansi Standard? Since
          that's about 99.9% of them (since we're constantly told you cant ask
          programming questions here - only pure C ones), then I suspect you'll
          be a busy little bee.

          Wouldn't it have been so much nicer of you to say:

          "Good morning, this issue confuses a lot of C prgroammers. Here is a
          link to the FAQ which might help".

          Because one thing is common knowledge and "boring" to you, doesnt mean
          it is to someone new who comes here for help. If that is your attitude
          then I suggest you don't bother trying to help.

          Have a good day now

          Comment

          • John Bode

            #6
            Re: Array name as pointers


            Richard G. Riley wrote:[color=blue]
            > On 2006-03-26, Martin Ambuhl <mambuhl@earthl ink.net> wrote:[color=green]
            > > newgoat wrote:[color=darkred]
            > >> As far as I understand, in "int arr[10]", the name of the integer array
            > >> "arr"
            > >> is equivalent to the pointer to the first element of the array. But is
            > >> "arr"
            > >> really a pointer, identical as "int *arr;" ?[/color]
            > >
            > > No. This question is so dead and boring it makes the parrot look
            > > lively. Do you imagine you are the first with this thought? It is to
            > > avoid repeatedly answering such things that we have a FAQ
            > ><http://c-faq.com/>. Please check it before posting.[/color]
            >
            > I assume you will be as rude to everyone else in this NG whose
            > questions are already answered in the FAQ and the Ansi Standard?[/color]

            God, I hope so.
            [color=blue]
            > Since
            > that's about 99.9% of them (since we're constantly told you cant ask
            > programming questions here - only pure C ones), then I suspect you'll
            > be a busy little bee.
            >[/color]

            The focus of this newsgroup is the C programming language, not
            applications that just happen to be written in C. Why is that so hard
            for people to understand?
            [color=blue]
            > Wouldn't it have been so much nicer of you to say:
            >
            > "Good morning, this issue confuses a lot of C prgroammers. Here is a
            > link to the FAQ which might help".
            >
            > Because one thing is common knowledge and "boring" to you, doesnt mean
            > it is to someone new who comes here for help. If that is your attitude
            > then I suggest you don't bother trying to help.
            >
            > Have a good day now[/color]

            I've been following this newsgroup since around 1994, and I have to
            say, after 12 years of people asking the same exact questions the same
            exact way, it's hard to stay civil. And people have good days and bad
            days; I've seen Martin be just as pleasant as you wished everyone would
            be.

            It is simply a part of usenet etiquette to lurk a while, see if your
            question has already been addressed (through the wonders of Google
            search), and read the newsgroup FAQ if one exists. Given that the FAQ
            for this particular newsgroup gets posted twice a month, it's not
            entirely unreasonable to be annoyed when someone asks a question that
            it addresses.

            It's also hard to stay pleasant with all the self-appointed 'net
            nannies boo-hooing about how *rude* we're all being.

            Comment

            • Richard G. Riley

              #7
              Re: Array name as pointers

              On 2006-03-26, John Bode <john_bode@my-deja.com> wrote:[color=blue]
              >
              > Richard G. Riley wrote:[color=green]
              >> On 2006-03-26, Martin Ambuhl <mambuhl@earthl ink.net> wrote:[color=darkred]
              >> > newgoat wrote:
              >> >> As far as I understand, in "int arr[10]", the name of the integer array
              >> >> "arr"
              >> >> is equivalent to the pointer to the first element of the array. But is
              >> >> "arr"
              >> >> really a pointer, identical as "int *arr;" ?
              >> >
              >> > No. This question is so dead and boring it makes the parrot look
              >> > lively. Do you imagine you are the first with this thought? It is to
              >> > avoid repeatedly answering such things that we have a FAQ
              >> ><http://c-faq.com/>. Please check it before posting.[/color]
              >>
              >> I assume you will be as rude to everyone else in this NG whose
              >> questions are already answered in the FAQ and the Ansi Standard?[/color]
              >
              > God, I hope so.[/color]

              Then you need to step back and reconsider.
              [color=blue]
              >[color=green]
              >> Since
              >> that's about 99.9% of them (since we're constantly told you cant ask
              >> programming questions here - only pure C ones), then I suspect you'll
              >> be a busy little bee.
              >>[/color]
              >
              > The focus of this newsgroup is the C programming language, not
              > applications that just happen to be written in C. Why is that so hard
              > for people to understand?[/color]

              What was not "C" in the OP?
              [color=blue]
              >[color=green]
              >> Wouldn't it have been so much nicer of you to say:
              >>
              >> "Good morning, this issue confuses a lot of C prgroammers. Here is a
              >> link to the FAQ which might help".
              >>
              >> Because one thing is common knowledge and "boring" to you, doesnt mean
              >> it is to someone new who comes here for help. If that is your attitude
              >> then I suggest you don't bother trying to help.
              >>
              >> Have a good day now[/color]
              >
              > I've been following this newsgroup since around 1994, and I have to[/color]

              The old "long term service medal" does not wash. Sorry.
              [color=blue]
              > say, after 12 years of people asking the same exact questions the same
              > exact way, it's hard to stay civil. And people have good days and
              > bad[/color]

              Then dont respond. Let someone else who is less bored respond. By your
              rational there is no need for beginners guides because C has been
              around for so long.
              [color=blue]
              > days; I've seen Martin be just as pleasant as you wished everyone would
              > be.[/color]

              So what? Was he here? Sorry, but that doesnt in any way justify his
              reply to someone who came here in good faith looking for help. The
              first name terms suggest a certain affiliation with him : this is
              maybe the type of clique to which I referred.
              [color=blue]
              >
              > It is simply a part of usenet etiquette to lurk a while, see if your[/color]

              For you. Some people come hre to get an answer and then depart. If you
              dont want to , or cant, help the ignore if you have nothing civil to say.

              [color=blue]
              > question has already been addressed (through the wonders of Google
              > search), and read the newsgroup FAQ if one exists. Given that the FAQ
              > for this particular newsgroup gets posted twice a month, it's not
              > entirely unreasonable to be annoyed when someone asks a question that
              > it addresses.[/color]

              It is totally unreasonable. Not everyone is here for a month "lurking"
              before they post. Not all usenet servers duplicate all posts.
              [color=blue]
              >
              > It's also hard to stay pleasant with all the self-appointed 'net
              > nannies boo-hooing about how *rude* we're all being.
              >[/color]

              The last paragraph is particularly telling.

              Its really simple : if you can and want to then "help". If not,
              dont. There is nothing that ruins a thread more than the usual
              suspects piling in with their "read the fucking FAQ" type posts when
              other more tolerant posters have posted a link or help directly.

              If you dont't see that that you should take a break.

              Comment

              • RSoIsCaIrLiIoA

                #8
                Re: Array name as pointers

                On 26 Mar 2006 -0800, "John Bode" <john_bode@my-deja.com> wrote:
                [color=blue]
                >I've been following this newsgroup since around 1994, and I have to
                >say, after 12 years of people asking the same exact questions the same
                >exact way, it's hard to stay civil. And people have good days and bad
                >days; I've seen Martin be just as pleasant as you wished everyone would
                >be.
                >
                >It is simply a part of usenet etiquette to lurk a while, see if your
                >question has already been addressed (through the wonders of Google
                >search), and read the newsgroup FAQ if one exists.[/color]

                and if *all* the questions were "been addressed" ?
                in that case why to write and answer one more time? :)

                Comment

                • Martin Ambuhl

                  #9
                  Re: Array name as pointers

                  Richard G. Riley wrote:
                  [color=blue]
                  > I assume you will be as rude to everyone else in this NG whose
                  > questions are already answered in the FAQ and the Ansi Standard?[/color]

                  It is rude beyond belief to post in a newsgroup questions answered in
                  the FAQ. It is strange to find the even ruder "Richard G. Riley"
                  thinking that pointing out that posters should have checked the FAQ is
                  rude.

                  Comment

                  • Richard G. Riley

                    #10
                    Re: Array name as pointers

                    On 2006-03-26, Martin Ambuhl <mambuhl@earthl ink.net> wrote:[color=blue]
                    > Richard G. Riley wrote:
                    >[color=green]
                    >> I assume you will be as rude to everyone else in this NG whose
                    >> questions are already answered in the FAQ and the Ansi Standard?[/color]
                    >
                    > It is rude beyond belief to post in a newsgroup questions answered in
                    > the FAQ. It is strange to find the even ruder "Richard G. Riley"
                    > thinking that pointing out that posters should have checked the FAQ is
                    > rude.[/color]

                    I think you should go back and see what you wrote "Martin".

                    The fact that you think think the FAQ is accessible to or even known
                    to newbies who come here says more about you than it does the newcomer
                    who comes here in the earnest hope of finding some help.

                    Did it even cross your mind that not all usenet users have web access?

                    Did it ever even cross your mind that a newbie might not even know
                    what to look for in the FAQ? Probably not.

                    You did not point him to the FAQ : you tried to make him look like an
                    incompetent idiot for not having (a) known about it and (b) not having
                    used it. I wont bother quoting you : it's all in the thread.

                    Interestingly enough there was a long enough thread reently about
                    similar stuff with pointers and arrays : I noticed you didnt come
                    haranging some of the regulars who were contributing then.

                    So to sum up : help or dont help. You chose the later but in a more
                    condescending and negative way than simply ignoring the poster or just
                    pointing him amicably to the correct section in the FAQ.

                    Comment

                    • santosh

                      #11
                      Re: Array name as pointers

                      Martin Ambuhl wrote:[color=blue]
                      > Richard G. Riley wrote:[color=green]
                      > > I assume you will be as rude to everyone else in this NG whose
                      > > questions are already answered in the FAQ and the Ansi Standard?[/color]
                      >
                      > It is rude beyond belief to post in a newsgroup questions answered in
                      > the FAQ.[/color]
                      <snip>

                      I don't see anything "rude" much less "rude beyond belief" to post a
                      FAQ. It's tiresome and exasperating no doubt to long time regulars, but
                      it's too idealistic to expect every newbie to find *and* check the
                      entire FAQ before posting. If it's too much for you to take, a better
                      course would be to simply ignore the poster in question or even
                      killfile him, (hey it's your newsreader and it's your loss...or gain),
                      or perhaps send him a private mail, but to insult and ridicule him in a
                      public newsgroup upon his (possibly) first post is "rude beyond
                      belief".

                      Comment

                      • Mark McIntyre

                        #12
                        Re: Array name as pointers

                        On Sun, 26 Mar 2006 16:00:50 +0200, in comp.lang.c , "Richard G.
                        Riley" <rgrdev@gmail.c om> wrote:
                        [color=blue]
                        >The old "long term service medal" does not wash. Sorry.[/color]

                        And yet every day, /you/ move a step closer to people's killfiles.
                        [color=blue][color=green]
                        >>
                        >> It is simply a part of usenet etiquette to lurk a while, see if your[/color]
                        >
                        >For you.[/color]

                        No, generally. Why not go read up on it?
                        [color=blue][color=green]
                        >>it's not
                        >> entirely unreasonable to be annoyed when someone asks a question that
                        >> it addresses.[/color]
                        >
                        >It is totally unreasonable.[/color]

                        You presumably have the patience of a saint, and don't mind someone
                        asking you, "are we nearly there yet" every thirty seconds from about
                        five minutes after departure. The rest of us are mortals.
                        [color=blue]
                        >Its really simple : if you can and want to then "help". If not,
                        >dont.[/color]

                        He did help. Your posts on the other hand have been useless.
                        [color=blue]
                        >There is nothing that ruins a thread more than the usual
                        >suspects piling in with their "read the fucking FAQ" type posts[/color]

                        Yes, there's plenty. Such as trolls, abusive newbies, idiots, and
                        incompetents. Frankly, pointing people at hte FAQ is entirely
                        appropriate.
                        Mark McIntyre
                        --
                        "Debugging is twice as hard as writing the code in the first place.
                        Therefore, if you write the code as cleverly as possible, you are,
                        by definition, not smart enough to debug it."
                        --Brian Kernighan

                        Comment

                        • Martin Ambuhl

                          #13
                          Re: Array name as pointers

                          Richard G. Riley wrote:[color=blue]
                          > On 2006-03-26, Martin Ambuhl <mambuhl@earthl ink.net> wrote:
                          >[color=green]
                          >>Richard G. Riley wrote:
                          >>
                          >>[color=darkred]
                          >>>I assume you will be as rude to everyone else in this NG whose
                          >>>questions are already answered in the FAQ and the Ansi Standard?[/color]
                          >>
                          >>It is rude beyond belief to post in a newsgroup questions answered in
                          >>the FAQ. It is strange to find the even ruder "Richard G. Riley"
                          >>thinking that pointing out that posters should have checked the FAQ is
                          >>rude.[/color]
                          >
                          >
                          > I think you should go back and see what you wrote "Martin".[/color]

                          Assholes who do nothing to help the original poster, telling them
                          nothing about where the FAQ is, what questions might be relevant, or
                          what normal postign is should just keep quiet. Some of them, like
                          "Richard G. Riley", while contributing *nothing* snipe at those who do
                          help. Yes, you are a rude and ignorant person.
                          [color=blue]
                          > The fact that you think think the FAQ is accessible to or even known
                          > to newbies who come here says more about you than it does the newcomer
                          > who comes here in the earnest hope of finding some help.[/color]

                          This is akin to "Hey, I'm an American. How was I supposed to know you
                          English drive on the wrong side of the road." A poster old enough to be
                          posting here is old enough to know what is expected.
                          [color=blue]
                          > Did it even cross your mind that not all usenet users have web access?[/color]
                          [color=blue]
                          >
                          > Did it ever even cross your mind that a newbie might not even know
                          > what to look for in the FAQ? Probably not.[/color]

                          Did you ever grow a brain? Since when is news.announce.n ewusers not
                          accessible to newbies?

                          [color=blue]
                          > You did not point him to the FAQ :[/color]

                          OK. You are a dmanable liar. There are four links to the FAQ,
                          including three to specific questions pertaining to his problem. It is
                          now completely clear that you are an antisocial troll who has *no*
                          interest in the truth. Goodbye.

                          Comment

                          • Default User

                            #14
                            Re: Array name as pointers

                            Mark McIntyre wrote:
                            [color=blue]
                            > On Sun, 26 Mar 2006 16:00:50 +0200, in comp.lang.c , "Richard G.
                            > Riley" <rgrdev@gmail.c om> wrote:[/color]

                            [who cares]
                            [color=blue]
                            > And yet every day, you move a step closer to people's killfiles.[/color]

                            Just do it, and stop feeding the troll.



                            Brian

                            --
                            If televison's a babysitter, the Internet is a drunk librarian who
                            won't shut up.
                            -- Dorothy Gambrell (http://catandgirl.com)

                            Comment

                            • Default User

                              #15
                              Re: Array name as pointers

                              Martin Ambuhl wrote:
                              [color=blue]
                              > Richard G. Riley wrote:[color=green]
                              > >On 2006-03-26, Martin Ambuhl <mambuhl@earthl ink.net> wrote:[/color][/color]

                              [who cares]
                              [color=blue]
                              > OK. You are a dmanable liar.[/color]


                              Please don't feed the troll.



                              Brian

                              Comment

                              Working...