My little Program is build this way:
I have an Object
Elementthat is defined as following:struct element { element* next; } typedef element;My Program is calling this recursive function...
int dosomething(element* a) { if (a != NULL) return dosomething(a->next); else return 0; }In the main function:
int main(void) { element* a = (element *) malloc(sizeof(element)); a-> next = (element *) malloc(sizeof(element)); cout << dosomething(a) << endl; return 0; }
When running this Program, I get:
Segmentation fault: 11
So, a and a->next is defined. a->next->next should be NULL, so the function should just return 0?
Why isn't this working?