c - 错误 : invalid type argument of unary '*' (have 'int' )

标签 c pointers struct

error: invalid type argument of unary '*' (have 'int')

struct test_t {
    int var1[5];
    int var2[10];
    int var3[15];
}

test_t* test;
test->var1[0] = 5;

我该如何解决这个问题?

最佳答案

你应该写:

struct test_t* test;

或者使用typedef如果您想避免每次声明该类型的变量时都编写 struct:

typedef struct test_t {
    int var1[5];
    int var2[10];
    int var3[15];
} test_t;

test_t* test;

旁注:在 C++ 中,结构名称位于常规命名空间中,因此在声明该类型的变量之前无需编写 struct

关于c - 错误 : invalid type argument of unary '*' (have 'int' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20656874/

相关文章:

c - 在Eclipse中调试C程序找不到命令行参数文件

c - 如何更改作为参数传递的变量的值?

c - 如何在automake c项目中获取调试符号?

delphi - 使用例程的结构和参数的另一个问题

c++ - 二叉搜索树,分配指向模板化结构节点的指针

c - 如何向双链表添加新元素

在 C 中为结构创建堆栈

c - 将函数指针分配给另一个函数内的函数

c - 使用结构进行动态内存分配

c - 将一般深度的嵌套指针传递给 C 中的函数