📄 sizeof.cpp
字号:
//这个程序在本书所带软盘中,文件名为SIZEOF.CPP
//这个程序利用sizeof和sizeof()来显示各种数据类型所占内存字节数。
#include <iostream.h>
void main(void)
{
char ch = 'a';
int num = 32767;
short snum = 100;
long lnum = 99999;
float pi = 3.141596;
double real = 3e10;
int char_bytes, int_bytes, short_bytes, long_bytes, float_bytes, double_bytes;
cout << " 字符型数据所占字节数: " << sizeof(char) << endl;
cout << " 整数型数据所占字节数: " << sizeof(int) << endl;
cout << " 短整型数据所占字节数: " << sizeof(short) << endl;
cout << " 长整型数据所占字节数: " << sizeof(long) << endl;
cout << " 浮点型数据所占字节数: " << sizeof(float) << endl;
cout << "双精度型数据所占字节数: " << sizeof(double) << endl;
char_bytes = sizeof ch;
int_bytes = sizeof num;
short_bytes = sizeof snum;
long_bytes = sizeof lnum;
float_bytes = sizeof pi;
double_bytes = sizeof real;
cout << endl;
cout << " 字符型变量ch所占内存字节数: " << char_bytes << endl;
cout << " 整型变量num所占内存字节数: " << int_bytes << endl;
cout << " 短整型变量snum所占内存字节数: " << short_bytes << endl;
cout << " 长整型变量lsum所占内存字节数: " << long_bytes << endl;
cout << " 浮点型变量pi所占内存字节数: " << float_bytes << endl;
cout << "双精度型变量real所占内存字节数: " << double_bytes << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -