Difference in behavior of char array and string pointer [closed]?

Up vote -4 down vote favorite share g+ share fb share tw.

The below code works fine if I try declaring variable "name" as "char name". Otherwise it throws a runtime exception shown below. What would be the reason for such behavior?

Void main() { char* name = "hello"; printf("\n %s", name); *(name+2) = 'm'; // exception occurs here...! tried using name2 = 'm' printf("\n%s", name); getch(); } Runtime Exception: "Unhandled exception at 0x012c37fe in trial. Exe: 0xC0000005: Access violation writing location 0x012c5756" c arrays pointers char link|improve this question asked Mar 26 at 17:02karan punjabi174.

C-faq.com/strangeprob/strlitnomod.html – cnicutar Mar 26 at 17:03 stackoverflow.com/q/7886972/557306 stackoverflow.com/q/1880573/557306 stackoverflow.com/q/2938895/557306 – sidyll Mar 26 at 17:05 string literals are read only, this falls to C basic knowledge. – AoeAoe Mar 26 at 17:08 correction: string literals are implementation defined, mostly hardcoded and readonly. – AoeAoe Mar 26 at 17:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions