c - 给指针赋值?

标签 c pointers struct structure kernighan-and-ritchie

我在丹尼斯里奇那里找到了这个,

struct rect r , *rp = r;

那么这四个表达式是等价的:

  1. r.pt1.x
  2. rp->pt1.x
  3. (r.pt1).x
  4. (rp->pt1).x

因为运算符从左到右关联。
不应该是struct rect *rp = &r吗?

最佳答案

绝对——需要地址运算符,otherwise you get a compile-time error :

incompatible types when initializing type ‘struct rect *’ using type ‘struct rect’

关于c - 给指针赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16675860/

相关文章:

c - 微 Controller 内存分配

c++ - 指针不更新它在 void 函数内指向的值

c++ - 用于通过 char 快速访问 glpyh 纹理的数据结构

c - 使用 void 函数指向数组

c++ - 如何从动态库中调用未知函数?

c - 非托管结构作为托管的返回值

c++ - 类中的默认安全参数

function - Golang 包结构返回缓冲区

c - Sublime Text 3 在 OS X 上使用传递的参数编译并运行(在终端中)C

c - 如何找到数组的大小(从指向数组第一个元素的指针)?