See the code below:
#include <vector>
#include <iostream>
int main(int argc, char *argv[]) {
std::vector<double> obj(10,0);
std::cout << &obj << std::endl;
std::cout << &obj[0] << std::endl;
}
I want to know the difference between these two addresses & thanks!
As I know, for a array like a[5], &a <=> &a[0] <=> a.
&objis the address of the vector itself, while the&obj[0]is the address of the data inside the vector.Arrays are nothing but data stored in them, so adress of array is effectively the same as adress of the data in it, while vector allocates its internal data on heap.