//i was creating a linked list and tranverse it
but in the while condition in the function , i was confused about wheater to put temp!=NULL or temp!=NULL. both showed different output. please help out. why they are different . . . . . .
#include <stdio.h>
#include <stdlib.h>
struct brick
{
int data;
struct brick * next; // self refrencing pointer
};
void printval(struct brick * temp);
void printval(struct brick * temp)
{
int i = 0;
while (temp != NULL)
{
printf("elements at index %d=%d \n", i, temp->data);
temp = temp->next;
i++;
}
}
int main()
{
struct brick *first, *second, *third;
first = (struct brick *)malloc(sizeof(struct brick));
second = (struct brick *)malloc(sizeof(struct brick));
third = (struct brick *)malloc(sizeof(struct brick));
first->data = 1;
first->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;
printval(first);
return 0;
}