By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

y++

P: n/a
what's the difference between "y++" and "y=y+1"?

Mar 16 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"ARMAS" <sm********@gmail.comwrote:
what's the difference between "y++" and "y=y+1"?
Ignoring stupid homework niggles, nothing whatsoever.

Richard
Mar 16 '07 #2

P: n/a
Richard Bos wrote:
"ARMAS" <sm********@gmail.comwrote:
>what's the difference between "y++" and "y=y+1"?

Ignoring stupid homework niggles, nothing whatsoever.
Um ... does

The value of the expression `y++` is the original
value of `y`, while the value of the expression `y=y+1`
is the new value of `y`.

count as a "stupid homework niggle"?

--
Chris "electric hedgehog" Dollin
"Go not to the Elves for counsel, for they will answer both no and yes."
/The Lord of the Rings/

Mar 16 '07 #3

P: n/a
Chris Dollin <ch**********@hp.comwrote:
Richard Bos wrote:
"ARMAS" <sm********@gmail.comwrote:
what's the difference between "y++" and "y=y+1"?
Ignoring stupid homework niggles, nothing whatsoever.

Um ... does

The value of the expression `y++` is the original
value of `y`, while the value of the expression `y=y+1`
is the new value of `y`.

count as a "stupid homework niggle"?
Yes. _As written_, those two do the same thing. _In context_ they might
do completely different things - you might, for example, also #define y
call_a_complex_function(pointer_to_binary_tree) - but outside of
homework problems or job applications, I expect such a context to be
given with the problem.

Richard
Mar 16 '07 #4

P: n/a
In article <45****************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
>what's the difference between "y++" and "y=y+1"?
Ignoring stupid homework niggles, nothing whatsoever.
>Um ... does

The value of the expression `y++` is the original
value of `y`, while the value of the expression `y=y+1`
is the new value of `y`.

count as a "stupid homework niggle"?
>Yes. _As written_, those two do the same thing. _In context_ they might
do completely different things - you might, for example, also #define y
call_a_complex_function(pointer_to_binary_tree) - but outside of
homework problems or job applications, I expect such a context to be
given with the problem.
_As written_, they do the same thing as foo=76. _In context_ - for
example if the variable y is used somewhere else - they may do
different things.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 16 '07 #5

P: n/a
Richard Bos wrote:
Chris Dollin <ch**********@hp.comwrote:
>Richard Bos wrote:
"ARMAS" <sm********@gmail.comwrote:

what's the difference between "y++" and "y=y+1"?

Ignoring stupid homework niggles, nothing whatsoever.

Um ... does

The value of the expression `y++` is the original
value of `y`, while the value of the expression `y=y+1`
is the new value of `y`.

count as a "stupid homework niggle"?

Yes.
OK. You niggle more than I, then.
_As written_, those two do the same thing. _In context_ they might
do completely different things - you might, for example, also #define y
call_a_complex_function(pointer_to_binary_tree) - but outside of
homework problems or job applications, I expect such a context to be
given with the problem.
I find this argument uncompelling, since the value of an expression
is an important property of it, and using the value of an expression
a very common context.

I note that the expressions `y++` and `(y++, 0)` do the same thing
as written, but would hesitate to describe their differences as
a niggle.

--
Chris "electric hedgehog" Dollin
"You're not supposed to /think/ about it, you're supposed to say NO!"
Jill Swinburn, /The Beiderbeck Connection/

Mar 16 '07 #6

P: n/a

"ARMAS" <sm********@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
what's the difference between "y++" and "y=y+1"?
A program that will tell you the difference
between the values of the two expressions
y++ and y=y+1 :

#include <math.h>
#include <stdio.h>

int main()
{
int init = 0;
int y = init;
int a = y++;
y = init;
int b = y = y + 1;

printf("%d\n", abs(a - b);
return 0;
}

-Mike
Mar 16 '07 #7

P: n/a
Mike Wahler said:
printf("%d\n", abs(a - b);
return 0;
}

-Mike
Mike - could you use this? )
No charge.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 16 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.