Problem in pointing to next address in linked list

Hi

Consider the following piece of code: -

int main()
{
lst *start = NULL, temp1=NULL;
lst *temp;

for (int i=0;i<10;i++)
{
temp->data = i=2;
temp->next = start;
start = temp;
}

temp1=start;

while (temp1=NULL)
{
for (i=0; i<10; i++)
{
cout << i << ". " << temp->data <<endl;
temp1 = temp1->next;
}
}

return 0;

}

It giving the output as 11 repeatedly. I dont understand why start is not pointing to the next address location.
Can anybody help.

Thanks
Niti
That code is totally, completely wrong.

First of all, temp is uninitialized before it is dereferenced. Secondly, the for() loop does not build a list of 10 nodes,
even if there weren't memory stomps. Thirdly, the while() loop should never execute since the condition is an
assignment, not a comparison, and the result of the expression will be false to begin with.

Topic archived. No new replies allowed.