Q:

possible reason of crash of following code?

I tested the following code on two different compilers, it crashed on first but worked fine on second?
The code is 
char *str="testing";
*str='b';
printf("%c",*str);

output : crashed on first compiler
b on second compiler
What may be the possible reason of crash?

A:

The reason for the crash is that writing into a string literal's memory is undefined behavior. Your code *str='b' writes directly into the first char of memory allocated to the string literal. C allows compilers to place the content of literals into the memory area that is protected from writing. Writing anywhere in that region causes a segmentation fault.
Change the declaration to
char str[]="testing";

to avoid the error. If you declare str as a char array (as opposed to a char pointer) the compiler generates code to copy the content of str into writable memory, thus avoiding the error when you write to str.

