Sunday, June 1, 2008

Improper Declaration causing Core Dump in C

Question: Why the following code dumps core:-
struct linkedlist
int *element;
struct linkedlist *link;
/*...main starts here...*/


Answer: Did you notice the missing ';' after the struct definition (before main)? That's the reason. In the above case, it assumes that main returns a struct of type 'linkedlist'.


No comments: