What is this behaviour in code?

@codingblockscpp
see there two things in a vector, one is size and other is capacity. Size denotes the number of elements currently present in the vector while capacity denotes the maximum elements it can have.

So with the help of reserve keyword you are declaring its capacity. So actually there are no elements present in the vector<vector> ‘arr’, so doing arr[i] doesn’t mean anything. So what you need to do here is take all the elements of a every array in some temporary , vectortemp, then do arr.push_back(temp). So in this way your code will work fine.

I have also done these changes in your code, you can also have a look at it https://ide.codingblocks.com/s/242940

@codingblockscpp
also please mark the doubt as resolved if it is clear now, if not then you can ask your doubt.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.