Priority of operator in c++ and C#

  • Thread starter Thread starter Arash_89
  • Start date Start date
A

Arash_89

Guest
Hello,
In the first code in C++, I expected 27 and it's true and in C# is 26.(I'm understand and I'm fine with this output in C# and C++)
But main problem here:

Why in the third code in C++ we have 24? I expected it was 22. (In C# y is 22 and I'm fine with this output)

Thank in advance

void main()
{
{
int x = 2;
int y = (5 * x++) + (3 * ++x) + x++;
cout << y ; // y is 27 and it's OK
}
}

public static void Main(String[] args)
{
{
int x = 2;
int y = (5 * x++) + (3 * ++x) + x++;
Console.WriteLine(y); //It's OK.
}

}



void main()
{
{
int x = 2;
int y = (5 * x++) + (3 * ++x);
cout << y ; // 24 and I expected 22 ??
}
}

public static void Main(String[] args)
{
{
int x = 2;
int y = (5 * x++) + (3 * ++x);
Console.WriteLine(y); It's 22 and It's OK.
}

}




1498354.jpg

Continue reading...
 
Back
Top