// why is temp2 not getting updated? It points to a[0].
struct man {
int pos;
struct man* next;
};
int main()
{
int i;
struct man* a[100];
struct man* temp2;
for (i=0;i<100;i++)
{
a[i] = (struct man*)malloc(sizeof(struct man));
a[i]->pos = i+1;
}
for (i=0;i<100;i++)
a[i]->next=a[(i+1)%100];
struct man* temp = a[0];
while (1)
{
temp->next = temp->next->next;
if(temp->next==temp) {
temp2=temp;
break;
}
}
printf("%d",temp2->pos);
return 0;
}