64,664
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int start = 1;
vector<int> v1(100);
v1.push_back(1); //
cout<<v1.size()<<endl; // 101
cout<<v1.capacity()<<endl; // 200
int end = 1;
cout<<sizeof(v1)<<endl; // 12
cout<<sizeof(start)<<endl; // 4
cout<<&start-&end<<endl; //9
cout<<"After reserve"<<endl;
v1.reserve(1000);
cout<<v1.size()<<endl; //101
cout<<v1.capacity()<<endl; //1000
cout<<sizeof(v1)<<endl; //12
system("PAUSE");
return 0;
}
#pragma pack(1)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int start = 1;
vector<int> v1(100);
v1.push_back(1); //
cout<<v1.size()<<endl; // 101
cout<<v1.capacity()<<endl; // 200
int end = 1;
cout<<sizeof(v1)<<endl; // 16
cout<<sizeof(start)<<endl; // 4
printf("%d\n",(unsigned int)&start-(unsigned int)&end); //20
cout<<&start-&end<<endl; //5
cout<<"After reserve"<<endl;
v1.reserve(1000);
cout<<v1.size()<<endl; //101
cout<<v1.capacity()<<endl; //1000
cout<<sizeof(v1)<<endl; //16
system("PAUSE");
return 0;
}