fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct struct1
  6. {
  7. vector<unsigned> vec1;
  8. };
  9.  
  10. int main() {
  11.  
  12. vector<struct1> vecStruct1;
  13. struct1 obj1Struct1;
  14. struct1 obj2Struct1;
  15. vecStruct1.push_back(obj1Struct1);
  16. vecStruct1.push_back(obj2Struct1);
  17.  
  18. cout << "Before resizing the vector:" << endl;
  19. cout << "Address of vecStruct1[0]:" << &vecStruct1[0] << endl;
  20. cout << "Address of vecStruct1[1]:" << &vecStruct1[1] << endl;
  21. cout << "Capacity of the vector in vecStruct1[0]:" << vecStruct1[0].vec1.capacity() << endl;
  22. cout << "Capacity of the vector in vecStruct1[1]:" << vecStruct1[1].vec1.capacity() << endl;
  23. cout << "Address of the 0th internal vector:" << &(vecStruct1[0].vec1[0]) << endl;
  24. cout << "Address of the 1st internal vector:" << &(vecStruct1[1].vec1[0]) << endl;
  25. cout << endl;
  26.  
  27.  
  28. vecStruct1[0].vec1.resize(1000);
  29.  
  30. cout << "After resizing vecStruct1[0]:" << endl;
  31. cout << "Address of vecStruct1[0]:" << &vecStruct1[0] << endl;
  32. cout << "Address of vecStruct1[1]:" << &vecStruct1[1] << endl;
  33. cout << "Capacity of the vector in vecStruct1[0]:" << vecStruct1[0].vec1.capacity() << endl;
  34. cout << "Capacity of the vector in vecStruct1[1]:" << vecStruct1[1].vec1.capacity() << endl;
  35. cout << "Address of the 0th internal vector:" << &(vecStruct1[0].vec1[0]) << endl;
  36. cout << "Address of the 1st internal vector:" << &(vecStruct1[1].vec1[0]) << endl;
  37. cout << endl;
  38.  
  39.  
  40. vecStruct1[1].vec1.resize(2000);
  41.  
  42. cout << "After resizing vecStruct1[1]:" << endl;
  43. cout << "Address of vecStruct1[0]:" << &vecStruct1[0] << endl;
  44. cout << "Address of vecStruct1[1]:" << &vecStruct1[1] << endl;
  45. cout << "Capacity of the vector in vecStruct1[0]:" << vecStruct1[0].vec1.capacity() << endl;
  46. cout << "Capacity of the vector in vecStruct1[1]:" << vecStruct1[1].vec1.capacity() << endl;
  47. cout << "Address of the 0th internal vector:" << &(vecStruct1[0].vec1[0]) << endl;
  48. cout << "Address of the 1st internal vector:" << &(vecStruct1[1].vec1[0]) << endl;
  49. cout << endl;
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
Before resizing the vector:
Address of vecStruct1[0]:0x98fc018
Address of vecStruct1[1]:0x98fc024
Capacity of the vector in vecStruct1[0]:0
Capacity of the vector in vecStruct1[1]:0
Address of the 0th internal vector:0
Address of the 1st internal vector:0

After resizing vecStruct1[0]:
Address of vecStruct1[0]:0x98fc018
Address of vecStruct1[1]:0x98fc024
Capacity of the vector in vecStruct1[0]:1000
Capacity of the vector in vecStruct1[1]:0
Address of the 0th internal vector:0x98fc038
Address of the 1st internal vector:0

After resizing vecStruct1[1]:
Address of vecStruct1[0]:0x98fc018
Address of vecStruct1[1]:0x98fc024
Capacity of the vector in vecStruct1[0]:1000
Capacity of the vector in vecStruct1[1]:2000
Address of the 0th internal vector:0x98fc038
Address of the 1st internal vector:0x98fcfe0