Search code examples
cansi-c

Why the temp pointer points to 0 instead 3?


Solving an exercise I got stuck in a problem that I was unable to identify. I have some code that needs to store a given pointer on a tempNode. Instead of it, the pointer structure receives int 0, where x is 3.

for (int i = 0; i <= MAX_NUM; i++) {
        if (y->item == x) {
            printf("y: %d\n", y->item);
            printf("x: %d\n", x);
            tempNode->item == y->item;
            tempNode->next == y->next;
            y = y->next;
            printf("tempNode: %d\n", tempNode->item);
        }

        y = y->next;
}

Solution

  • The correct answer, thanks to Sami the identified it.

    tempNode->item = y->item;
    tempNode->next = y->next;