why sizeof(tp2) I get 32 instead of 28, int(4) + int(4) + float(4) + complex(16) == 28,but this code get 32
#include <iostream>
#include <tuple>
#include <string>
#include <complex>
using namespace std;
int main() {
// cout << sizeof(int) << endl;
// cout << sizeof(string) << endl;
// tuple<int, int, string> tp;
// cout << sizeof(tp) << endl;
tuple<int, int, float, complex<double>> tp2;
cout << sizeof(tp2) << endl;
return 0;
}
I guess the reason is the memory aligment, but I do not know is it right?
New contributor
21g is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.