C/c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bidhut Karki
    New Member
    • Feb 2012
    • 1

    C/c++

    /* This program is giving me output 8, I don't know how it is possible. I am using Turbo C++ complier.. Please Explain it to me */

    #include<stdio. h>
    void main()
    {
    int a,b=2;
    a = (++b)+(++b);
    printf("%d",a);
    }

    Output: 8
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    8 is as good as anythig else. Modifying a variable more than once in a C++ statement produces indeterminate results since the compiler if free to evaluate the variable in any order.

    Comment

    Working...