#include <iostream>
#include <windows.h>
using namespace std;
#define my_sizeof(L_Value) (char* )(&L_Value + 1) - (char* )&L_Value
int main(void)
{
int i;
double f;
double a[4];
double* q;
TCHAR szText[]={"我是你的大皇冠"};
cout<<my_sizeof(i)<<endl;
cout<<my_sizeof(f)<<endl;
cout<<my_sizeof(a)<<endl;
cout<<my_sizeof(q)<<endl;
cout<<my_sizeof("aadf")<<endl;
cout<<my_sizeof(szText)<<endl;
cout<< (&i + 1) - &i<<endl;
cout<< (BYTE*)(&i + 1) - (BYTE*)&i<<endl;
/*
这里的+1是,数据类型+1后的地址。比如int+1,就是2个int
*/
return 0;
}
/*
2015年4月10日14:30:29
程序执行结果如下:
4
8
32
4
5
15
1
4
请按任意键继续. . .
*/
不用sizeof()函数求当前主机上的一个int占用几个字节
最新推荐文章于 2021-05-17 02:25:02 发布