Two posers for you
What is the output of the following code, and why?
[Update: By “why“, I mean “what part of the C# spec controls this behavior?“]
class Test
{
public static void Main()
{
int z = 2;
z += ++z+5*z++;
System.Console.WriteLine("Yak! {0}", z);
}
}
What about this code?
class Test
{
public static void Main()
{
int z = 2;
z += (5*z++)+(++z);
System.Console.WriteLine("Yak! {0}", z);
}
}
Extra credit: What is the defined output for C++, and why?