What array structure is in C# but not in C/C++/Java? -
i'm preparing exams , there's question can't find answer to. read bunch of articles, closest found was
arrays in c# come in 3 flavors: single-dimensional, multidimensional rectangular arrays (like c++ multidimensional arrays), , jagged arrays (arrays of arrays).
so suggests there's no jagged arrays in c++, exists in java. thing c# can have non-zero array lower-bound(like a[-1,3] or a[4,9]. considered different array structure?
c++
- so suggests there's no jagged arrays in c++
by same reading, block of text suggests c++ doesn't have single dimensional arrays. absurd!
c++ has both... can make int**
, pointer pointer (so "array" of pointers, "array" of "arrays"), in c# can have int[][]
, array of int[]
. c++ see various examples here. note syntax more c c++... in c++ should use std::array
, here.
- another thing c# can have non-zero array lower-bound(like a[-1,3] or a[4,9])
this doesn't exist in c++... internally implemented in c# same code implements multi dimensional arrays, , exist historical reasons (pseudo-compatibility old versions of vb)
java
java doesn't have multi-dimensional arrays (see here). have jagged arrays, trick: if want can initialize jagged array has elements of same size in single command or if have different sizes/some of them can null
, can initialize them manually.
int[][] num = new int[4][2];
vs
int[][] num = new int[4][]; num[0] = new int[1]; num[1] = new int[2]; num[2] = new int[3]; num[3] = new int[4];
so in end
c# java c++ single-dimensional array x x x multi-dimensional array x x si.di. non-zero based array x mu.di. non-zero based array x jagged array x x x
Comments
Post a Comment