0

I don't really understand why that small piece of code brings to the access violation exception. Could anyone explain, please

char* str = "freedPood";
*str = 'A';
Andrey Lyubimov
  • 663
  • 6
  • 22
  • 2
    Look at the answer to [**this question**](https://stackoverflow.com/questions/14499300/why-segmentation-fault-in-following-code), and *dozens* of similar questions. The [selected answer](http://stackoverflow.com/a/14499366/1322972) is *precisely* why your code faults. I'm somewhat surprised your C++ compiler didn't issue at least a warning informing you of assigning a `const char*` to a `char *`. Perhaps make it a habit to turn up your warning levels to pedantic levels. – WhozCraig Jun 08 '15 at 04:52
  • @WhozCraig thanks, man! – Andrey Lyubimov Jun 08 '15 at 04:57
  • Sometimes, constants are. – David Schwartz Jun 08 '15 at 05:04

0 Answers0