0

From this given array:

    int arr[][3] = {{1,2},{3,4,5},{5}}

I have few questions:

1) From looking at the definations and way of declaration of jagged and Multidimensional array, I think this one is the Multidimensional array, am I right?

2) How to find the: sizeof(arr), arr[0][2] & arr [1][2] These are the options:

a) 6 0 4 b) 6 1 5 c)18 0 5 d)18 1 5

I know we find the size of array by multiplying the size of datatype (Int is 4 bytes) with the total elements so here it will be 9 (because of Multidimensional array) * 4 = 36 (got the hint from https://stackoverflow.com/a/51479846/5698871) , But there is no 36 in available options , for remaining two values arr[0][2] & arr [1][2] , it will be I think 0 5, But how come 18 is the size here?

Please any explanation will be really helpful. Thanks.

shahtaj khalid
  • 476
  • 7
  • 24
  • From the looks of it you are working in a language that does not have jagged arrays as a first class type - what language are you using? add it in the tags. – kabanus Nov 18 '18 at 13:41
  • @kabanus This is in the past papers of one of the test I'm preparing for, These is no language specification. So that's why just the calculations are required and have to choose from these 4 options. – shahtaj khalid Nov 18 '18 at 13:49
  • Well, it looks like C or C++. Without a language requirement you should probably type code that looks more like pseudo code, and define what `int arr..` line means - you **could** define it to be a jagged array in some made up langauage. This is legal code in newer C for example, but is a regular multi-dimensional array. `sizeof` is a `C` operator. As such this looks like a C question - otherwise it is unclear. – kabanus Nov 18 '18 at 13:55
  • Also, you linked to a `c++` question so... – kabanus Nov 18 '18 at 13:57

0 Answers0