2 questions; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

2 questions;

Why does the first code output More instead of Zero? static void Func(int a) { a %=2; return; } public static void Main (string[] args) { int a = 100; Func(a); Console.Write(a == 0 ? "Zero" : "More"); } And why does this code output 1 instead of 6? public static void Main(String[] args) { int a = 1, b; b = increase(a); Console.Write(a); } public static int increase(int a) { a += 5; return a; }

7th Jan 2021, 7:22 AM
eMBee
eMBee - avatar
2 Answers
+ 7
M○|-|FΞY 🇳🇬 1st part : the function Func is a void function and u are trying to return sth , that's an error .For the desired output either pass the variable by reference instead of value or change the function returning the processed variable and use that to compare with 0 . 2nd part : Output the variable" b "instead of " a ".
7th Jan 2021, 7:26 AM
Alphin K Sajan
Alphin K Sajan - avatar
0
Alphin K Sajan what do you mean by pass the variable by reference instead of value
7th Jan 2021, 10:58 AM
eMBee
eMBee - avatar