+ 3

C# - A strange assignment

Why on Earth in this code is y assigned 6? In effect, result is 60. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static int Multi(int a, int b, int c){ return (a * b * c); } static void Main(string[] args) { int x,y,z; x = 5; y = x++; //so, y is assigned 6? z = x/3; Console.Write(Multi(x,y,z)); } } }

20th Apr 2019, 8:01 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
4 Respostas
+ 1
x = 6 y = 5 z = x/3 = 6/3 = 2 6 * 5 = 30 30 * 2 = 60 Why should it be 50
20th Apr 2019, 9:29 PM
sneeze
sneeze - avatar
+ 3
I agree with you but so, Multi should return 50. Instead, it returns 60!
20th Apr 2019, 9:26 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 3
I confused, sorry ☺️
22nd Apr 2019, 5:28 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
0
in addtion to ~ swim ~ Y is 5 X is 6 https://code.sololearn.com/c6uy4RskK38L
20th Apr 2019, 8:44 PM
sneeze
sneeze - avatar