This is a function (last) that returns the oldest value in linked list (the last node):
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int val;
struct node *next;
}Elem, *Pointer;
Pointer init() { return NULL; }
void last(Pointer l)
{
while (l != NULL)
{
l = l->next;
}
printf("%d",l->val);
}
int main(void) {
Pointer myl =
insert(3, insert(7, insert(5,
insert(11, insert(1, init ())))));
last(myl);
}
so the function (last) takes a pointer that points to a linked list, and in a while loop it moves the pointer to the last node and then prints its value.
Error is: exited, segmentation fault.