0

How many elements are there in array int arr[2][3]?(in C++)

I thought the array is not yet filled so no elements are present, but the ans is 6=2x3. Would be helpful if someone clarifies whether the vacancy of array means it has element or not?

11th Dec 2018, 4:37 PM
I_am_IRONMAN
I_am_IRONMAN - avatar
3 Answers
+ 7
Here in C++ in case of arr[2][3] It is statically allocated memory The size needs to be specify before compile time Hence 2×3 =6 memory is already allocated
11th Dec 2018, 4:48 PM
Rstar
Rstar - avatar
+ 2
It kinda have a value, but just a garbage left in memory. I dont think it has any use at all You can try this code to see them. int s=10; int arr[s]; for(int i=0;i<s;i++) cout<<arr[i]<<"\n"; And its not only applied to array, but any uninitialized variable.
11th Dec 2018, 4:45 PM
Taste
Taste - avatar
+ 1
Oh thank you guys
11th Dec 2018, 4:52 PM
I_am_IRONMAN
I_am_IRONMAN - avatar