increment and decrement operators

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeromegg
    New Member
    • Sep 2018
    • 1

    increment and decrement operators

    Is there a difference between Turbo C++ and Dev C++ because

    Code:
    int s,r=35;
    s=(++r)+(r++);
    cout<<s;
    (In Turbo C it results 72)
    (In DevC++ it results 73)

    How ?
    Last edited by zmbd; Sep 8 '18, 02:08 AM.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This is garbage code:

    Code:
    s=(++r)+(r++);
    C does not guarantee the order in which the statement is processed. Maybe right to left, maybe left to right, maybe some other order. Different compilers will get different answers.

    Never use increment and decrement operators to a variable more than once in a statement.

    Comment

    • john665544
      New Member
      • Sep 2018
      • 1

      #3
      The increment and decrement operator function has no difference between Turbo C++ and Dev C++. You can check the full details from outlook support to get the full details of this.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        The OP says the two compilers produce different results.

        If you parse right to left you get 73. If you parse left to right you get 72.

        Again, it comes down to modifying a variable more than once in the same statement. That's a no-no.

        Comment

        Working...