我遇到了指针问题。 这是我想要的一个例子
struct Book
{
char name[10];
int price;
}
int main()
{
struct Book b[10]; //Array of structure variables
struct Book* p; //Pointer of Structure type
p = &b; --- HERE is the ERROR
}
这是错误部分
p = &b;
最佳答案
b
是一个数组,它本身可以衰减为指针变量。通过编写 &b
,您实际上获取了该指针的地址,然后您最终得到了指向指针的指针。只需编写 p = b
就足够了。
关于c - C 编程中的结构指针有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35287267/