0

Why is this showing me wrong?

I did the take a shortcut in c# I answered all questions but this question is showing me 24 wrong as answer. Why? https://www.sololearn.com/post/505759/?ref=app

25th Aug 2020, 4:57 PM
Ved Thaker
Ved Thaker - avatar
1 Answer
+ 5
The out keyword causes arguments to be passed by reference. static int Test(out int x, int y = 4){ x = 6; return x * y; } static void Main(string[] args) { int a; int z = Test(out a); Console.WriteLine(a+z); } Explanation: a is pass to Test as out in x parameter, in Test function, we have x = 6 (since a is passed as out its value get changed to 6, because x and a are reference type any changes you make to x will change a also and vice versa) Now Test returns x * y which 6 * 4 = 24 to the z variable in our main function. therefore we have, a = 6 z = 24 Console.WriteLine(6+24); ==> 30
25th Aug 2020, 5:09 PM
minirkk
minirkk - avatar