c - 一对变量/结构的偏移量是否相同?

标签 c pointers struct

假设我有这个

typedef struct{
  int n;
  double* x;
}array;

array a;
double* a_;

array b;
double* b_;

&a_-&a == &b_-&b 是否对每对数组/double* 依此类推?

在否定的情况下,如何确保这一点?

最佳答案

您不能依赖具有任何特定关系的单独变量的地址。此外,您不能有效地将地址减去不同的变量。

也许如果您能弄清楚为什么您想要这个(您想要做什么?),就有可能真正提供帮助。

关于c - 一对变量/结构的偏移量是否相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15161936/

相关文章:

c - 如何在 C 中初始化匿名结构的第二个成员?

c - 位操作 :print the next smallest and largest numbers with same no of 1 bits

php - 平行于PHP的 "explode"in C : Split char* into char* using delimiter

c - 在 C 中实现椭圆方程的正确方法是什么?

c - 为什么不建议在 C 中使用指针进行数组访问

c++ - const char * 与其他指针不同吗?

C:从指向结构的指针访问指向结构元素的指针

c - 初学者C分配