When creating a linked list in the following way, I understand everything that is happening except for:
curr = (item *)malloc(sizeof(item));
I get that you are allocating enough memory for the size of an item struct, but what exactly are you doing with (item *) ? Is this meant to be pointer notation or multiplication?
#include<stdlib.h>
#include<stdio.h>
struct list_el {
int val;
struct list_el * next;
};
typedef struct list_el item;
void main() {
item * curr, * head;
int i;
head = NULL;
for(i=1;i<=10;i++) {
curr = (item *)malloc(sizeof(item));
curr->val = i;
curr->next = head;
head = curr;
}
curr = head;
while(curr) {
printf("%d\n", curr->val);
curr = curr->next ;
}
}