c - 如何访问 C 结构体中的指针成员?

标签 c pointers member member-pointers

struct sample
{
    int a;
    char b;
    float c;
    int *al;
    union un
    {
        int a;
        char c;
        float f;
    }*ptr;
}test;

如何访问结构成员“al”和 union 成员 a,c,f?

最佳答案

与其他人没有区别:

  1. 访问al

    test.al
    

    如果你想要al的值,可以通过*(test.al)获取。

  2. 访问acf

    test.ptr->a;
    test.ptr->c;
    test.ptr->f;
    

关于c - 如何访问 C 结构体中的指针成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22141541/

相关文章:

字符* (*车辆)[][5];动态分配

java - 如何从父类(super class)中的方法访问(隐藏)子类中的成员变量?

在 Makefile 中处理链接的正确方法?

c - 更新字符串的单个字符

c - 为什么我得到 "ERROR : request for member stringLength and name in something not a structure or union"?

c++ - QWidget::layout() 不能返回 QGridLayout?

C++类成员回调

C++使成员对象未命名

c - 如果未找到匹配项,sscanf 会触摸指针吗?

C++ 和 SDL2 - "Auto-Generate"使用了 DLL?