size of vector and array not same why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

size of vector and array not same why?

so here a example code #include <iostream> #include <vector> using namespace std; int main() { int myArray[3]{ 5, 10, 15 }; vector<int> myVector(begin(myArray), end(myArray)); for (int x : myVector) cout << x << " "; // 5 10 15 for(int i : myArray) cout<<i<<" "; cout<<"\n"<<sizeof(myVector); cout<<"\n"<<sizeof(myArray); } //output //5 10 15 5 10 15 //24 //12

20th Jul 2022, 12:32 PM
Samir_Shah
Samir_Shah - avatar
2 Answers
+ 3
to determine size or length of vector, use vector.size(); hope this clears... https://stackoverflow.com/questions/34024805/c-sizeof-vector-is-24
20th Jul 2022, 12:49 PM
Jayakrishna 🇮🇳
+ 1
thanks :)
21st Jul 2022, 7:15 AM
Samir_Shah
Samir_Shah - avatar