Re: use of ++i, i++

From: Richard Cavell (richardcavell_at_mail.com)
Date: 02/27/05


Date: Sun, 27 Feb 2005 13:52:56 +1100

On 27/2/05 6:28 AM, Greenhorn wrote:
> hi,
> From reading some guides i understood that prefix, postfix operate
> this way, former executes the increment right away, latter executes the
> increment after the immediately after the immediately following end of
> statement. Is that correct ?
>
> If i go by that rule, the below two statements are equivalent
>
> for(i=0;i < 1;i++)
> printf("The first value printed for i is %d", i);
>
> for(i=0;i < 1;++i)
> printf("The first value printed for i is %d", i);

Yes, but consider this:

int a = ++i;
int b = i++;

And also consider what happens when i is not an integer. i can be any
given class, which might do anything at all.



Relevant Pages

  • Re: use of ++i, i++
    ... >> From reading some guides i understood that prefix, postfix operate ... >> this way, former executes the increment right away, latter executes the ...
    (comp.lang.c)
  • use of ++i, i++
    ... From reading some guides i understood that prefix, postfix operate ... this way, former executes the increment right away, latter executes the ...
    (comp.lang.c)
  • Re: Challenge: Loop in Common Lisp and in Java
    ... > 2) Use postfix for increment unless required. ... Postfix is less efficient than prefix. ... but I don't like making the compiler work that hard just ...
    (comp.lang.lisp)
  • Re: [PHP] counting with leading zeros
    ... given the prefix 'bar' i do ... /* increment, format with leading zero again if necessary, ... sort($filenames); ... I'm content to not worry about overflow in this ...
    (php.general)
  • Re: Reset a number back to 1 at the beginning of the year
    ... > I have a project I am working on where the client requires a document ... > number to increment by 1 each time and the prefix of the number is the ... Google for "Access Custom Autonumbers" for more details. ...
    (microsoft.public.access.modulesdaovba)