Sunday, May 22, 2011

Back to the basics

what will happen?

main
{
char *p="safer";
p[0]='j';
p[1]='j';
puts(p);
}

1 comment:

  1. Depends on the compiler. Many modern compilers store string literals in read-only memory. Any modification will result in access violation exception. We can catch such exceptions using kernel API like installExceptionHandlers() if supported.

    There are few compilers that store the string literals in RW memory. The program works as expected in such cases.

    ReplyDelete