Again I have a very stupid question, I just can't find an answer to. This time I want to know, why the member method works. Especially the while
loop in the member method. So why does the following code work:
while(current){
if(current->i==a){
return 1;
}
...
}
Why does the argument while(current)
not produce a infinite execution?
This is the whole program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct liste{
int i;
struct liste *next;
};
struct liste *m [4];
struct liste *current;
int hash(int b){
printf("%i\n",sizeof(m));
return b%sizeof(m);
}
int insert(int a){
struct liste *new = malloc(sizeof(struct liste));
if(new){
new->i = a;
new->next=m[hash(a)];
m[hash(a)] = new;
return 1;
}
return 0;
}
int member(int a){
current = m[hash(a)];
while(current){
if(current->i==a){
return 1;
}
current = current->next;
}
return 0;
}