-2

I have a class 'node' which has two members data and *next. When I am accessing data using pointer then it is working fine whereas when i am accessing it using double pointer , it is throwing an error . Can anyone explain me why this is happening?

class node{
public:
    int data;
    node *next;
};

push(&a,8);

void push(node **p , int x){
*p->data = 11;
}

Why this p->data showing error: request for member ‘data’ in ‘ p’, which is of pointer type ‘node*’

1 Answers1

3

Because *p->data is *(p->data), not (*p)->data.

Read about operator precedence.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055