
Untitled
By: a guest on
Jul 1st, 2012 | syntax:
None | size: 1.08 KB | hits: 14 | expires: Never
Are multi-dimensional arrays zero-inited?
public class Foo {
static int[][] arr;
public static void bar() {
arr = new int[20][20];
// in the second run of Foo.bar(), the value of arr[1][1] is already 1
// before executing the next statement!
arr[1][1] = 1;
}
}
public class Foo {
static int[][] arr;
public static void bar() {
arr = new int[20][20];
System.out.println("Before: " + arr[1][1]);
// in the second run of Foo.bar(), the value of arr[1][1] is already 1
// before executing the next statement!
arr[1][1] = 1;
System.out.println("After: " + arr[1][1]);
}
public static void main(String[] args) {
bar();
bar();
}
}
Before: 0
After: 1
Before: 0
After: 1
// in the second run of Foo.bar(), the value of arr[1][1] is already 1
// before executing the next statement!
public class Foo {
public static void main(String[] args) throws Exception {
bar();
bar();
}
static int[][] arr;
public static void bar() {
arr = new int[20][20];
System.out.println(arr[1][1]);
arr[1][1] = 1;
}
}