【发布时间】:2020-05-16 09:48:17
【问题描述】:
/* The structure of the Linked list Node is as follows:
struct Node
{
int val;
struct Node *next;
Node(int data){
val = data;
next = NULL;
}
};
*/
void intersection(Node **head1, Node **head2,Node **head3)
{
cout<<*head1->val;
}
上面的代码不起作用,但是当我使用另一个指针 Node* h1=*head1; 然后打印它的值时它工作正常。在这两个代码中,我要打印的值是相同的,那么为什么上面的代码是错误的;
/* The structure of the Linked list Node is as follows:
struct Node
{
int val;
struct Node *next;
Node(int data){
val = data;
next = NULL;
}
};
*/
void intersection(Node **head1, Node **head2,Node **head3)
{
Node* h1=*head1;
cout<<h1->val;
}
【问题讨论】:
-
请附上minimal reproducible example 并解释“不工作”是什么意思
-
@idclev463035818 这不是完整的代码。注释块只是为了让读者清楚了解链表的结构
标签: c++ c++11 pointers operator-precedence dereference