order of evaluation of C-expression

This is a discussion on order of evaluation of C-expression within the C Programming forums, part of the General Programming Boards category; Can anyone explain why output of following program excerpt gives value '6' for x ? int x=8; x-=--x-x--;//how this statement ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    1

    order of evaluation of C-expression

    Can anyone explain why output of following program excerpt gives value '6' for x ?

    int x=8;
    x-=--x-x--;//how this statement will be processed
    printf("%d",x);

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,993
    Because the behaviour is undefined as x is modified more than once between consecutive sequence points.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 11-11-2009, 01:27 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 08:15 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. sizeof and Expression Evaluation
    By Dave_Sinkula in forum C Programming
    Replies: 2
    Last Post: 08-11-2003, 07:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21