tricky output ???

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

    tricky output ???

    #include<stdio. h>
    int main(void){
    int i=5;
    printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
    return 0;
    }


    This gives me : 4 5 5 5 5

    How ???

    Can anyone please give me some hint as to why I am getting this ??

    Thanks & regards,
    Onkar

  • Richard Heathfield

    #2
    Re: tricky output ???

    onkar said:
    #include<stdio. h>
    int main(void){
    int i=5;
    printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
    return 0;
    }
    >
    >
    This gives me : 4 5 5 5 5
    >
    How ???
    >
    Can anyone please give me some hint as to why I am getting this ??
    What answer were you expecting, and why?


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

    Comment

    • onkar

      #3
      Re: tricky output ???

      On Feb 16, 11:17 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
      onkar said:
      >
      #include<stdio. h>
      int main(void){
      int i=5;
      printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
      return 0;
      }
      >
      This gives me : 4 5 5 5 5
      >
      How ???
      >
      Can anyone please give me some hint as to why I am getting this ??
      >
      What answer were you expecting, and why?
      >
      --
      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

      I was expecting 4 5 5 4 5

      Comment

      • Keith Thompson

        #4
        Re: tricky output ???

        onkar <onkar.n.m@gmai l.comwrites:
        #include<stdio. h>
        int main(void){
        int i=5;
        printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
        return 0;
        }
        >
        >
        This gives me : 4 5 5 5 5
        [...]

        The FAQ for this newsgroup is at <http://www.c-faq.com/>.

        You desperately need to read section 3. (Then read the rest of it.)

        --
        Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
        Nokia
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        • Ian Collins

          #5
          Re: tricky output ???

          onkar wrote:
          #include<stdio. h>
          int main(void){
          int i=5;
          printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
          return 0;
          }
          >
          What's brought all these daft UB questions out of the woodwork this week?

          --
          Ian Collins.

          Comment

          • Richard Heathfield

            #6
            Re: tricky output ???

            Ian Collins said:
            onkar wrote:
            >#include<stdio .h>
            >int main(void){
            > int i=5;
            > printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
            > return 0;
            >}
            >>
            What's brought all these daft UB questions out of the woodwork this week?
            What makes you think there's anything special about this week? :-)

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

            Comment

            • Randy Howard

              #7
              Re: tricky output ???

              On Sat, 16 Feb 2008 01:04:31 -0600, Ian Collins wrote
              (in article <61ng7uF1ui98vU 11@mid.individu al.net>):
              onkar wrote:
              >#include<stdio .h>
              >int main(void){
              >int i=5;
              >printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
              >return 0;
              >}
              >>
              What's brought all these daft UB questions out of the woodwork this week?
              New semester started recently.



              --
              Randy Howard (2reply remove FOOBAR)
              "The power of accurate observation is called cynicism by those
              who have not got it." - George Bernard Shaw





              Comment

              • Richard

                #8
                Re: tricky output ???

                Richard Heathfield <rjh@see.sig.in validwrites:
                onkar said:
                >
                >#include<stdio .h>
                >int main(void){
                > int i=5;
                > printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
                > return 0;
                >}
                >>
                >>
                >This gives me : 4 5 5 5 5
                >>
                >How ???
                >>
                >Can anyone please give me some hint as to why I am getting this ??
                >
                What answer were you expecting, and why?
                it should be blatantly obvious why he doesn't think this is right. The
                fact he would be wrong is besides the point.

                Comment

                • santosh

                  #9
                  Re: tricky output ???

                  onkar wrote:
                  #include<stdio. h>
                  int main(void){
                  int i=5;
                  printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
                  return 0;
                  }
                  >
                  >
                  This gives me : 4 5 5 5 5
                  >
                  How ???
                  >
                  Can anyone please give me some hint as to why I am getting this ??
                  >
                  Thanks & regards,
                  Onkar
                  This guy is doubtless a troll. He keeps posting such stupid questions
                  even after months of being told about the FAQ.

                  Comment

                  • Kenneth Brody

                    #10
                    Re: tricky output ???

                    Richard wrote:
                    >
                    Richard Heathfield <rjh@see.sig.in validwrites:
                    >
                    onkar said:
                    #include<stdio. h>
                    int main(void){
                    int i=5;
                    printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
                    return 0;
                    }
                    >
                    >
                    This gives me : 4 5 5 5 5
                    >
                    How ???
                    >
                    Can anyone please give me some hint as to why I am getting this ??
                    What answer were you expecting, and why?
                    >
                    it should be blatantly obvious why he doesn't think this is right. The
                    fact he would be wrong is besides the point.
                    But, until one starts to think about "why" he thinks the answer
                    should be what he thinks it should be, you cannot explain to him
                    the flaws in his thinking.

                    --
                    +-------------------------+--------------------+-----------------------+
                    | Kenneth J. Brody | www.hvcomputer.com | #include |
                    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
                    +-------------------------+--------------------+-----------------------+
                    Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>


                    Comment

                    • Richard Heathfield

                      #11
                      Re: tricky output ???

                      Kenneth Brody said:
                      Richard wrote:
                      >>
                      >Richard Heathfield <rjh@see.sig.in validwrites:
                      >>
                      onkar said:
                      >
                      >#include<stdio .h>
                      >int main(void){
                      > int i=5;
                      > printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);
                      > return 0;
                      >}
                      >>
                      >>
                      >This gives me : 4 5 5 5 5
                      >>
                      >How ???
                      >>
                      >Can anyone please give me some hint as to why I am getting this ??
                      >
                      What answer were you expecting, and why?
                      >>
                      >it should be blatantly obvious why he doesn't think this is right. The
                      >fact he would be wrong is besides the point.
                      >
                      But, until one starts to think about "why" he thinks the answer
                      should be what he thinks it should be, you cannot explain to him
                      the flaws in his thinking.
                      In fact, his answer to my question gave me a clue as to what he was
                      thinking. He might equally have said: 5 6 6 5 5, in which case my answer
                      would have been slightly different.

                      As usual, Richard Riley is sniping ignorantly, caustically, and
                      uncomprehending ly at people who are actually supplying help, instead of
                      taking the risk of supplying help himself to those who are asking for it.
                      He may safely be ignored, since he never contributes anything useful.

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

                      Comment

                      Working...