#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)版本中有''''和'您需要將圓括號內的指針包圍起來,才能應用正確的運算符優先級。 –