[英]Structure pointer and its use
What is the meaning of this statement in C? 这个陈述在C中的含义是什么?
where fag
is structure and its pointer is pat
. fag
是结构,指针是pat
。
fag *pat = &h.device[d];
d = (pat - &(h.device[0]))/(sizeof(fag)) ;
fag *pat = &h.device[d];
takes the address od the d
th element of the said array. 获取所述数组的第
d
个元素的地址。
It can be used to ease the access to it. 它可以用来方便访问它。
If I do 如果我做
d = (pat - &(h.device[0]))/(sizeof(fag));
where I don't have access to the original d
, I get the index of the given entry, in the said array. 在我无法访问原始
d
,我得到了所述数组中给定条目的索引。
It takes the difference from "our" pointer to the original one. 它从“我们的”指针到原始指针的区别。
If I see it right, the division by sizeof fag
is wrong - the difference is already in terms of fag
size. 如果我看到它的权利,通过划分
sizeof fag
是错误的-不同的是已经在以下方面fag
大小。 Besides, &(h.device[0])
is exactly the same as h.device
, so 此外,
&(h.device[0])
与h.device
,所以
d = pat - h.device;
should be the right thing. 应该是正确的事情。 ( Thank you, WhozCraig. )
( 谢谢你,WhozCraig。 )
结构指针的一种可能用途可能是,如果要更改函数中结构的成员,则必须传递结构的地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.