设为首页 加入收藏

TOP

C++中的(unsigned int)&代表的意思
2015-07-24 05:45:52 来源: 作者: 【 】 浏览:5
Tags:unsigned int & 代表 意思

int  main()

{
using namespace std;
int i = 20;
int m = (unsigned int)&i; //注意这里的&符号
cout << m << endl;
}

&:表示引用的意思,表示m是i的一个别名,相当于人的小名。


再看下面的例子:

#include 
  
   

#define FIND(struc,e)  (int)&(((struc *)0)->e)

typedef struct {
	int  a;
	char b[20];
	double ccc;
}stu;

int main()
{
	printf("%d\n",FIND(stu,b[0]));
	printf("%d\n",FIND(stu,ccc));

	return 0;
}

  

这里定义了一个宏FIND,求结构体struc里的某个变量相对于struc的偏移量。

其中(struc *)0表示将常量0强制转化为struc *型指针所指向的地址;

&(((struc &)0)->e)表示取结构体指针(struc *)0的成员e的地址。

输出结果为:4 24


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA 766 - Sum of powers(伯努利.. 下一篇PKU 1276 Cash Machine

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: