Interview Questions

I just tried the code Why didn't it crash?

C Interview Questions and Answers


(Continued from previous question...)

I just tried the code Why didn't it crash?

Q: I just tried the code
char *p;
strcpy(p, "abc");

and it worked. How? Why didn't it crash?

A:You got lucky, I guess. The memory randomly pointed to by the uninitialized pointer p happened to be writable by you, and apparently was not already in use for anything vital.

(Continued on next question...)

Other Interview Questions