char c[]="opop";
c[2]='k';
But it should give a bus error,why does it work?
char c[]="opop";
c[2]='k';
But it should give a bus error,why does it work?
What you have is an array, not an string literal. It is perfectly valid code.
char *c="opop";
c[2]='k';
Would cause an Undefined Behavior and most likely a crash.
Good Read:
What is the difference between char a[] = "string"; and char *p = "string";