y++

C

Chris Dollin

Richard said:
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"?
 
R

Richard Bos

Chris Dollin said:
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
 
R

Richard Tobin

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"?
[/QUOTE]
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
 
C

Chris Dollin

Richard said:

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

Mike Wahler

ARMAS said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top