是否可以从varA和carB分配varC的值,而无需在C ++中更改vaarA和varB的值?

我试图从varA和varB分配varC的值,而不更改varA和varB的值。 但是,当为varC分配值时,似乎varA和varB随varC一起自动更改。 这是我的代码。

#include <iostream>
using namespace std;
main ()
{
    int varA = 10 ; // a = 10
    int varB = 10; // b = 10
    cout << "The exact value of varA is: " << varA <<'\n';
    cout << "The exact value of varB is: " << varB <<'\n';
    int varC = (++ ++ ++ ++ ++ ++ ++ ++ ++ ++ varA) += (varC = ++varB);
    cout << "After assigning the value for varC The value of varA is: " << varA <<'\n';
    cout << "After assigning the value for varC The value of varB is: " << varB <<'\n';

    cout << "The assigned value of varC is: " << varC <<'\n';
    cout << "The sum of varA, varB and varC is: " << varA + varB + varC << '\n';
    return 0;
评论