-3

Recently, I've been learning algorithms, so I try to code leetcode. There are some programs like

int pop(struct node ** top_pt){
//弹出数据并且释放内存
if (*top_pt==NULL){
    printf("stack overflow\n");
    exit(0);
}

struct Node *top=*top_pt;
//满递增
int res=top->val;

*top_pt=top->Next;
free(top);
return res;

}

so, what is the difference between the pointers like * and **?

fuz
  • 88,405
  • 25
  • 200
  • 352
Jean
  • 19
  • 1
  • 1
  • 6
  • 1
    possible duplicate of [How do pointer to pointers work in C?](http://stackoverflow.com/questions/897366/how-do-pointer-to-pointers-work-in-c) – EOF Sep 02 '15 at 12:26
  • 1
    possible duplicate of [Not able to understand the notations : \* and \*\* with pointers](http://stackoverflow.com/questions/29692986/not-able-to-understand-the-notations-and-with-pointers) – ameyCU Sep 02 '15 at 12:30
  • 是的呢,最近一直在学习算法,指针那部分看了不少,现在结构体指针又来了。掌握的不扎实呢。 – Jean Sep 02 '15 at 13:49

1 Answers1

0

Nothing really, a pointer is a pointer is a pointer, it's how you use it that makes all the difference.

This pattern (passing a pointer to a pointer to something) is a ways of emulating pass by reference (which C doesn't have) for a pointer. This means that when you change the pointer using e.g. *top_ptr = top->Next that change will be in the calling function as well.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621