0

(Spoiler Alert) Module 3's Final Question

"What is the output of this code? 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); }" I don't think I understand how this comes out to the answer it does. Please correct me if I'm wrong... I get that: "Test(out a)" will retrieve the value of "x * y", as that is the return statement. Which is 6 * 4 = 24, this will be assigned to "int z". However; I don't understand how "int a" gets a value. I'm not the best coder here, so please - if you can - break it down simplistically. Thankx in advance. (Obviously no quotations, but I figured that was necessary since I copy/pasted the problem. Also it makes it easier to read when explaining (I think)).

9th Feb 2017, 6:21 AM
William Draper
William Draper - avatar
9 Respostas
+ 8
Variable a gets a value in method Test. There is statement x = 6; in the definition of method, and when you call this method, you send variable a as output parameter, wich is x in definition, so a = 6.
9th Feb 2017, 9:28 AM
Kruno Bazalec
+ 10
a will take the value of out x which will be 6 --> so a=6 z will take the value of the function test which is x * y which is 6 * 4 = 24 so, z = 24 so, a + z = 6 + 24 = 30
22nd Aug 2018, 1:10 PM
Mohamed Ramadan El Geneidy‎
Mohamed Ramadan El Geneidy‎ - avatar
+ 6
answer: 30
10th Jul 2018, 10:28 AM
kodali.kavya
+ 1
The Test method assigns x to a. X=6, X=A, A=6. int a = 6 int z = (6*4) = 24 //since y is 4 by default, Test(out a) really reads Test(out a, 4) int (a+z) = 30
20th Nov 2018, 9:26 PM
Ray M
Ray M - avatar
+ 1
static
20th Mar 2019, 5:36 PM
Adelyn Kucey
Adelyn Kucey - avatar
0
WRONG, YOUR BAD EZ KID
19th Sep 2018, 9:28 AM
Damian .
Damian . - avatar
0
thanks dod
20th Apr 2019, 8:08 PM
Everything that comes to mind
Everything that comes to mind - avatar
0
Nice
25th Nov 2019, 10:24 AM
Gothandaraman P
Gothandaraman P - avatar
- 2
To find the largest of two variables int a=42; int b=88; (a>b)
10th May 2021, 5:21 PM
Prathmesh K Umredkar