I was trying to write a pop function which pops a node from a linked list by using a pointer to the head pointer of the linked list

My code was:

```
struct stack{
  char name;
  int  info;
  struct stack *next;
};
typedef struct stack s;

```

The first POP Function which i wrote was (this is my first time using pointer to pointer)

```
1) s *pop(s **ps){
     s **temp1;
     *temp1=NULL;
     *temp1=*ps;
     *ps=(*ps)->next;
    return *temp1;
}

```

rather this worked 

```
2)    s *pop(s **ps){
        s *temp2=NULL;
          temp2=*ps;
          *ps=(*ps)->next;
          return temp2;
    }

```

I am getting a segmentation fault for 1,whats going wrong?,Is there a better way to do this? 

I used the pointer to pointer method cos i have read pointers are passed by value so even if i change something in pop using temp variable the local change wont affect the actual one