Why 32 and not 45? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why 32 and not 45?

static int Func(int a = 3, int b = 7, int c =6){ return a + b * c; } static void Main() { int a=4; int b=5; int c=2; Console.Write(Func(c, b)); }

22nd Jun 2022, 1:23 PM
eMBee
eMBee - avatar
1 Answer
+ 4
Function parameters go in order. Names do not matter in particular, only the types. So in a more simple format, it works like: Func(1st place = 3, 2nd place = 7, 3rd place = 6) So what you passed as the first place get the assignment of a. What you passed as the second place parameter gets the assignment of b. Because you didn't not pass a parameter but have a default value for such an instance, what is being returned to you is: 2 + 5 * 6 And because of PEMDAS, it turns into: 2 + 30 And then your final result is: 32. Function parameters only care about the order of the values, the data type of the values and the values itself. The name is automatically reassigned based on what order they are passed through.
22nd Jun 2022, 1:59 PM
Justice
Justice - avatar