To access any random index in array, we access the following memory location :
a[i] = base address + (size of data_type) * i
This is the reason why arrays have only same type of data.
Now this works perfectly fine when we're working with primitive data types like int, char etc.
However, let's say I have an array of strings where size of each string is different :
string a[] = {"xyz", "abcde", "qwerty"}
How does this work inside memory? Since each string is taking different memory, how does this work out internally?
Edit :
Got the answer for strings. Strings have a constant size internally so it works out.
What happens in case of let's say array of vectors:
vector<int> v[5];
Do they also have a constant size internally?
std::stringinstances?!? I Don't get your question? If you want to determine the string size, you have to usestd::string::size(),sizeof(std::string)is constant.