This is an erroneous action, because a string literal of type "string" is actually a constant string that cannot be changed. It may well be placed in read-only memory.
And assigning it to a char* pointer formally allows you to change this string.
Only, unfortunately, VC ++ 2017 does not report any errors, and this assignment permits: (
Here, your program when compiling VC ++ 2017:
cl /EHsc /W4 test.cpp Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.13.26129 для x64 (C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены. test.cpp test.cpp(8): warning C4189: ch: локальная переменная инициализирована, но не использована Microsoft (R) Incremental Linker Version 14.13.26129.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:test.exe test.obj
const-const char * = "text";The fact is that the pointer really refers to a constant (such data cannot be changed, so the compiler reports this) - avp