#include <iostream.h>
int main()
{
cout << "The size of an int is:\t\t"<< sizeof(int) << " bytes.\n";
cout << "The size of a short intis:\t" << sizeof(short) << " bytes.\n";
cout << "The size of a long int is:\t"<< sizeof(long) << " bytes.\n";
cout << "The size of a char is:\t\t"<< sizeof(char) << " bytes.\n";
cout << "The size of a floatis:\t\t" << sizeof(float) << " bytes.\n";
cout << "The size of a double is:\t"<< sizeof(double) << " bytes.\n";
return 0;
}
解: 源程序:
#include <iostream.h> int main() { cout << "The size of an int is:\t\t"<< sizeof(int) << " bytes.\n"; cout << "The size of a short intis:\t" << sizeof(short) << " bytes.\n"; cout << "The size of a long int is:\t"<< sizeof(long) << " bytes.\n"; cout << "The size of a char is:\t\t"<< sizeof(char) << " bytes.\n"; cout << "The size of a floatis:\t\t" << sizeof(float) << " bytes.\n"; cout << "The size of a double is:\t"<< sizeof(double) << " bytes.\n"; return 0; }程序运行输出:
The size of an int is: 4 bytes.
The size of a short int is: 2 bytes.
The size of a long int is: 4 bytes.
The size of a char is: 1 bytes.
The size of a float is: 4 bytes.
The size of a double is: 8 bytes.