Please Help Me...

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
Timo
Learning poster
Posts: 70
Joined: Tue Oct 11, 2005 2:44 am
Location: Indonesia

Please Help Me...

Post by Timo » Wed Mar 15, 2006 8:56 am

I have a code like this :

Code: Select all


#include <stdio.h>

int main()
{
  int x,y;
   
  x=4;
  y=x++ * ++x;
  x=4;
  printf("%d %d\n",y,  x++ * ++x);

  return 0;
}

I think the result will be :
25 25

but when I test :
25 24

please explain to me ?
"Life is more beautiful with algorithm"

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Re: Please Help Me...

Post by sumankar » Wed Mar 15, 2006 9:20 am

Timo wrote:I have a code like this :

Code: Select all

[...]
  y=x++ * ++x;
  x=4;
  printf("%d %d\n",y,  x++ * ++x);
The nadir of Undefined Behaviour!
Multiple ambiguous side-effects within a single sequence point. For more:
http://c-faq.com/expr/evalorder2.html

Post Reply

Return to “C”