Could someone teach me the answer to this question? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Could someone teach me the answer to this question?

What is the output of this code? static int Vol(int x, int y=3, int z=1) { return x*y*z; } static void Main(string[] args) { Console.WriteLine(Vol(2, 4)); }

31st Aug 2016, 2:26 AM
Solarwolf2
Solarwolf2 - avatar
4 Answers
+ 4
The answer is 8 because x = 2, y = 4, z = 1. If we didn't pass any value to the parameter y, then the default value will be 3. In this case, variable y receives a value of 4, then y = 4 and variable z does not receive any value in calling method, default value of z will be used instead.
31st Aug 2016, 1:04 PM
Fung
Fung - avatar
0
Great...!
18th Aug 2017, 3:06 PM
cliff
0
Thanks for the answer
10th Dec 2020, 2:32 PM
Vinay pednekar
Vinay pednekar - avatar
0
Lol I still don't understand it but i'll move on
22nd Jul 2021, 3:45 PM
Tom McQueen
Tom McQueen - avatar