-----------------------std::vector<int>()-----------------------stack address is 1000 (metadata stored here)std::vector<int> v1; // v1 is created on stack at address 1000std::vector<int> v2 = v1; // Copy constructor is invoked // A new vector is created with the same content as v1 // Stored at a different stack address (e.g., 2000) // A new heap allocation is done for the elementsSo in the end:-----------------------std::vector<int> (v1)-----------------------stack address is 1000heap address (data) is 3000-----------------------std::vector<int> (v2)-----------------------stack address is 2000heap address (data) is 4000 (copied from 3000)And if you modify v1, it will not reflect in v2
-----------------------new std::vector<int>()-----------------------Heap address is 1000auto v1 = new std::vector<int>() // returns start addrees means 1000auto v2 = v1 // Points to 1000So in the end-----------------------new std::vector<int>()-----------------------Heap address is 1000It is pointed by both v1 and v2And if you modify in v1 it will reflect v2 because they pointing to same stuff
auto v1 = std::vector<int>;// fill v1auto v2 = v1;