Answers for "size of a 2d array"

1

length of 2d array c++

int rows = sizeof(arr) / sizeof(arr[0]); // returns rows
int col = sizeof(arr[0]) / sizeof(int); // returns col
Posted by: Guest on May-23-2020
1

2d array length in java

public static void main(String[] args) {

    int[][] foo = new int[][] {
        new int[] { 1, 2, 3 },
        new int[] { 1, 2, 3, 4},
    };

    System.out.println(foo.length); //2 // gives count of rows
    System.out.println(foo[0].length); //3 // gives count of columns for particular row
    System.out.println(foo[1].length); //4
}
Posted by: Guest on May-08-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language