<pre name="code" class="cpp">#include <iostream>
using std::cout; using std::cin; using std::endl;
#include <string>
using std::string;
#include <cstring>
#include <vector>
using std::vector;
#include <iterator>
using std::begin; using std::end;
#include <cstddef>
using std::size_t;
int main()
{
int ia;
cout << "the bytes of int is " << sizeof ia << endl;
short sa;
cout << "the bytes of short is " << sizeof sa << endl;
long la;
cout << "the bytes of long is " << sizeof la << endl;
long long lla;
cout << "the bytes of long long is " << sizeof lla << endl;
float fa;
cout << "the bytes of float is " << sizeof fa << endl;
double da;
cout << "the bytes of double is " << sizeof da << endl;
long double lda;
cout << "the bytes of long double is " << sizeof lda << endl;
return 0;
}
输出
the bytes of int is 4
the bytes of short is 2
the bytes of long is 4
the bytes of long long is 8
the bytes of float is 4
the bytes of double is 8
the bytes of long double is 12