i am having problem postfix and prefix works with multiplication operator
              x = 5;
              y = ++x * ++x;
as it's is prefix it will change and then use it so it should be like this y =6*7=42 but that's not the case it using same value for both incremented x i.e. y =7 * 7 =49
    #include<iostream>
        
            using namespace std;
        
            int main ()
        
            {
             int x, y;
                x = 5;
              y = ++x * ++x; //y =6*7=42 but output shows y=7 * 7=49
        
              cout << x<< y<<endl;
        
                x = 5;
        
                y = x++ * ++x; // y= 5 * 7= 35 which is correct 
        
                cout << x << y;
        
                return 0;
        
            }
    
    output:749
           735
Aucun commentaire:
Enregistrer un commentaire