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?
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
+ 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.
+ 1
Oh thank you guys