This program works correctly ...
C Interview Questions and Answers
(Continued from previous question...)
This program works correctly ...
Q: This program works correctly, but it dumps core after it finishes. Why?
struct list {
char *item;
struct list *next;
}
/* Here is the main program. */
main(argc, argv)
{ ... }
A: A missing semicolon at the end of the structure declaration causes main to be declared as returning a structure. (The connection is hard to see because of the intervening comment.) Since structure-valued functions are usually implemented by adding a hidden return pointer , the generated code for main() tries to accept three arguments, although only two are passed (in this case, by the C start-up code).
(Continued on next question...)
Other Interview Questions
|