首页 > 试题广场 >

C++有哪几种数据类型?简述其值域。编程显示你使用的计算机中

[问答题]
C++有哪几种数据类型?简述其值域。编程显示你使用的计算机中的各种数据类型的 字节数。
推荐

解: 源程序:

#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.

发表于 2018-05-07 20:57:57 回复(0)