effect of b = a++ + a++

Discussion in 'C Programming' started by Ravi, Jan 20, 2008.

  1. Ravi

    Ravi Guest

    what is the effect of fllowing code n values of a and b
    b = 0;
    a = 1;
    b = a++ + a++;
    Ravi, Jan 20, 2008
    #1
    1. Advertising

  2. Ravi wrote:
    > what is the effect of fllowing code n values of a and b
    > b = 0;
    > a = 1;
    > b = a++ + a++;


    Please refer to section 3 (Expressions) of the FAQ. Here is a link to
    the same: http://www.c-faq.com/expr/index.html.

    Regards,
    Vi
    Vimal Aravindashan, Jan 20, 2008
    #2
    1. Advertising

  3. Ravi

    friendfish Guest


    > what is the effect of fllowing code n values of a and b
    > b = 0;
    > a = 1;
    > b = a++ + a++;

    That is "(b= (a++)+(a++))", after that b=2 and a=3;
    friendfish, Jan 21, 2008
    #3
  4. On Mon, 21 Jan 2008 14:50:43 +0800,
    friendfish <> wrote:
    >
    >> what is the effect of fllowing code n values of a and b
    >> b = 0;
    >> a = 1;
    >> b = a++ + a++;

    > That is "(b= (a++)+(a++))", after that b=2 and a=3;


    Neither the C standard or the FAQ agree with you.

    Maybe on your particular compiler it works like that, but you have no
    guarantee that it will work like that anywhere else.

    See another post in this same thread for a reference to the C FAQ that
    explains why you should not do this.

    Martien
    --
    |
    Martien Verbruggen | Louis Pasteur's theory of germs is ridiculous
    | fiction -- Pierre Pachet, Professor of
    | Physiology at Toulouse, 1872
    Martien Verbruggen, Jan 21, 2008
    #4
  5. friendfish wrote:
    >> what is the effect of fllowing code n values of a and b
    >> b = 0;
    >> a = 1;
    >> b = a++ + a++;

    > That is "(b= (a++)+(a++))", after that b=2 and a=3;

    Not neccessarily. Read the FAQs as mentioned by a previous poster.

    Bye, Jojo
    Joachim Schmitz, Jan 21, 2008
    #5
  6. Ravi

    Randy Howard Guest

    On Mon, 21 Jan 2008 01:14:07 -0600, Joachim Schmitz wrote
    (in article <fn1go0$8qu$>):

    > friendfish wrote:
    >>> what is the effect of fllowing code n values of a and b
    >>> b = 0;
    >>> a = 1;
    >>> b = a++ + a++;

    >> That is "(b= (a++)+(a++))", after that b=2 and a=3;

    > Not neccessarily. Read the FAQs as mentioned by a previous poster.
    >


    I get this from the compiler:
    b.c: In function Œmain¹:
    ub.c:10: warning: operation on Œa¹ may be undefined

    'May' being an interesting spin on things.



    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
    Randy Howard, Jan 21, 2008
    #6
  7. Ravi

    Kaz Kylheku Guest

    On Jan 20, 3:04 am, Ravi <> wrote:
    > what is the effect of fllowing code n values of a and b
    > b = 0;
    > a = 1;
    > b = a++ + a++;


    The effect is that it stupefies the reader to the point that he's
    unable to read the FAQ or operate the Google search engine.
    Kaz Kylheku, Jan 21, 2008
    #7
  8. friendfish wrote:
    >
    >> what is the effect of fllowing code n values of a and b
    >> b = 0;
    >> a = 1;
    >> b = a++ + a++;

    > That is "(b= (a++)+(a++))", after that b=2 and a=3;


    No, after that the value of b is undefined. Please learn about sequence
    points.

    This is yet another example of a tiresome error adequately discussed in
    the FAQ. Unfortunately, the same people that "know" what this
    ill-formed code means are the same ones who won't bother reading the FAQ
    or following the newsgroup before posting.
    Martin Ambuhl, Jan 21, 2008
    #8
  9. Ravi

    Kaz Kylheku Guest

    On Jan 20, 10:50 pm, friendfish <> wrote:
    > > what is the effect of fllowing code n values of a and b
    > > b = 0;
    > > a = 1;
    > > b = a++ + a++;

    >
    > That is "(b= (a++)+(a++))", after that b=2 and a=3;


    Please don't answer questions in the newsgroup if you haven't read and
    understood the FAQ.

    You look like an ignorant ass who doesn't know anything, and can't be
    bothered to do as little as three minutes of basic research before
    submitting an article.
    Kaz Kylheku, Jan 21, 2008
    #9
  10. Ravi

    CBFalconer Guest

    friendfish wrote:
    >
    >> what is the effect of fllowing code n values of a and b
    >> b = 0;
    >> a = 1;
    >> b = a++ + a++;

    >
    > That is "(b= (a++)+(a++))", after that b=2 and a=3;


    No. The only effect is undefined behaviour. Anything at all can
    happen. You could find yourself 6 mos. pregnant (although the
    likelihood is probably low).

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Jan 21, 2008
    #10
  11. Ravi

    MisterE Guest

    "Ravi" <> wrote in message
    news:...
    > what is the effect of fllowing code n values of a and b
    > b = 0;
    > a = 1;
    > b = a++ + a++;


    just do b=a+a; a+=2; and stop being a **** head
    MisterE, Jan 25, 2008
    #11
  12. Ravi

    santosh Guest

    MisterE wrote:

    >
    > "Ravi" <> wrote in message
    >

    news:...
    >> what is the effect of fllowing code n values of a and b
    >> b = 0;
    >> a = 1;
    >> b = a++ + a++;

    >
    > just do b=a+a; a+=2; and stop being a **** head


    Neither will do what the OP's code does, simply because the OP code is
    undefined.
    santosh, Jan 25, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SEWilson

    Re: Flickering effect

    SEWilson, Aug 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,084
    SEWilson
    Aug 23, 2003
  2. chan
    Replies:
    1
    Views:
    3,760
    Nico Debeuckelaere
    Mar 4, 2004
  3. John E. Jardine

    s/// has apparent side effect on grep()

    John E. Jardine, Apr 12, 2004, in forum: Perl
    Replies:
    2
    Views:
    445
    John Jardine
    Apr 13, 2004
  4. Ryan McLean

    Problem with .aspx chenges taking effect

    Ryan McLean, Nov 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    321
    Ryan McLean
    Nov 26, 2003
  5. kai
    Replies:
    9
    Views:
    736
Loading...

Share This Page