# effect of b = a++ + a++

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

1. ### RaviGuest

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

Ravi, Jan 20, 2008

2. ### Vimal AravindashanGuest

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

3. ### friendfishGuest

> 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
4. ### Martien VerbruggenGuest

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
5. ### Joachim SchmitzGuest

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
6. ### Randy HowardGuest

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.

--
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Randy Howard, Jan 21, 2008
7. ### Kaz KylhekuGuest

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

Kaz Kylheku, Jan 21, 2008
8. ### Martin AmbuhlGuest

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
9. ### Kaz KylhekuGuest

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;

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
10. ### CBFalconerGuest

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>

--
Posted via a free Usenet account from http://www.teranews.com

CBFalconer, Jan 21, 2008
11. ### MisterEGuest

"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
12. ### santoshGuest

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