0
why isnt the output 6? or would it have print num and not x?
public class MyClass { public static void main(String[ ] args) { int x = 5; addOneTo(x); System.out.println(x); } static void addOneTo(int num) { num = num + 1; } }
8 Réponses
+ 1
You need to ude refernce, wtite the function like this: (int& num)
+ 1
~ swim ~
Ohh i didn't know that😐
+ 1
thanks anyways. to both of you.
+ 1
You have to use pass by reference method
+ 1
When we use to pass addres of variable x than any changes occured in x will also change the value of x in main function tooo
0
Oh it doesn't return anything from the method. Is that right?
0
ok thanks
0
thanks. i appreciate your answer