#include<stdio.h>
#include<stdlib.h>
struct test
{
int data;
struct test *next;
};
void main()
{
struct test *head=(struct test *)malloc(sizeof(struct test));
struct test **ref=&head;
head->data=5;
head->next=NULL;
printf("\n %d \n %d",head->data,head->next);
printf("\n %d \n %d",**ref->data,**ref->next);
}
说明:C指针双指针
我已经试过上述一段代码。
是不是**ref
是否与*head
相同?如果不是为什么?
此外,编译器在第二printf
引发错误说data
和next
不是structure
或union
的一部分。
欢迎来到Stack Overflow! [请参阅此讨论,为什么不在'C'中投射'malloc()'和family的返回值。](http://stackoverflow.com/q/605845/2173917)。 –
没有任何编程方面,如果'** ref与* head'相同,那么为什么你认为额外的'*'在那里呢? –
换句话说,在你的'printf(“\ n%d \ n%p”,(* ref) - > data,(* ref) - > next)版本中有''''和'您需要将圆括号内的指针包围起来,才能应用正确的运算符优先级。 –