0

I have the following code:

void randomfunction () {
 List x = [1,2,3];
 int y = 5;
 increment(x,y);
 print('x: $x\ny: $y');
}

// adds element '4' to list and increases the number by 5
void increment (list, number) {
 list.add(4);
 number += 10;
}

void main() {
 randomfunction();
}

When randomfunction() is called, the output is:

x: [1, 2, 3, 4]
y: 5

Why is it that increment() only affects the list and not the integer? My current understanding of it is that since both variables are local to increment(), increment shouldn't affect both x or y. Thank you!

Emmanuel
  • 165
  • 2
  • 13

0 Answers0