Im pretty new to C, and am looking for an explanation of why I am getting this error message.
Code:#include <stdlib.h> #include <stdio.h> struct node { int first; struct node *rest; }; struct node *cons(int fst, struct node *rst) { struct node *new = malloc(sizeof(struct node)); new->first = fst; new->rest = rst; return new; } struct node *insert(struct node *lst1, int n) { struct node *temp; temp->first = n; temp->rest = lst1; return temp; } int main(void) { struct node *a = cons(2,cons(3,cons(6,NULL))); struct node *c = insert(a, 10); }
This is the valgrind message I get:
I know this is a simple problem but I just don't understand what is going on!Code:= Use of uninitialised value of size 4 = at 0x80483FB: insert (test.c:19) = by 0x804845F: main (test.c:27) = Uninitialised value was created by a stack allocation = at 0x80483F2: insert (test.c:17) = Process terminating with default action of signal 11 (SIGSEGV) = Bad permissions for mapped region at address 0x8049FF4 = at 0x80483FB: insert (test.c:19) = by 0x804845F: main (test.c:27)



LinkBack URL
About LinkBacks



