Search code examples
javacarraysprogramming-languagesmultidimensional-array

2D Array - C vs Java


What is the difference between a Dynamic 2D Array in C (int **arr) and A 2D Array in Java (int [][]arr) ?

Is a 2D Array in C/C++ similar to a 2D Array in Java?


Solution

  • The answer will change according to part you want to compare.

    In Java, arrays are objects that have methods and attributes, however in C/C++ they are not objects.

    Both of them similar in a way that array dimension can be different. I mean arr[0] can be 3-dimensional, arr[1] 5-dimensional, etc.

    Java is checking array bounds therefore will throw exceptions if you try to reach an index outside of the array boundaries, however in C/C++ no exception will be thrown however, you might end up with an "segmentation fault".