Possible Duplicate:
Why don’t I get a segmentation fault when I write beyond the end of an array?
I was just playing with pointers when I realized that something strange was happening. I am aware that whenever we want to copy a string src to another string dst, using strcpy, for instance, we should allocate the required space for src.
char *dst,*src = "asdlskafksdhfklshfkshdkfhksdhfçsahdflçsdhfçklshadfç";
dst = (char*)malloc(1); //only one char allocated
strcpy(dst,src);
printf("dst=%s.\n",dst);
This code should not execute. However that is not happening. The code executes, copies successfully the src into dst and prints dst like a charm. Could someone of you, explain me why is this happening, please?