Doubt in array declaration inside a function

Hello, Why do we write a 2D array like

int a [ ] [ 100] inside a function declaration

but in case of a 1D array we don’t define the size of array

int a[ ]

I mean why we are defining the size in case of 2D array which is not required in case of 1D array ?

Hey @yashsharma4304
int arr[][]={1,2};
now how the compiler knows if its 2x1 or 1x2

So why only column size has to be mentioned. Why can’t we mention only the row size?
int arr[2][]={1,2,3,4,5,6,7,8};
now how the compiler knws if there are 5 elements in 1 row or 8 or xyz…
He can’t just simply dived total elements between different rows.

1 Like

If this resolves your query then please Hit a Like and mark this as resolved :slight_smile:

Ok. :slightly_smiling_face: :slightly_smiling_face:

1 Like