help with the array in the function

I wrote a simple function to return a array, but when I call this function I got a problem: Object reference not set to an instance of an object.
Can anybody help me to figure out this problem?

function TestArray () : int[] {
	var arr : int[];
	for (var i : int = 0; i < 4; i++) {
		arr[i] = 0;
	}
	return arr;
}

var arr : int[ ] = new int[5]; i think. That way you create the missing instance

Arrays are not “simple” data types (like int, float etc) so you have to create them with the “new” keyword.

I modify the second line of the code and it works fine now:

var arr : int[] = [0, 0, 0, 0];

But I’m still puzzled, Why do I need to assign values to the array? Can anyone explain for me? Thanks a lot;)

you dont have to: var arr: int[ ] = new int[5] will create an array with a length of 5

var arr: int[ ] = new int[5] {0,6,3,12,1} will initialize it with the values in brackets