const char* still modifies the pointed value

Why is the value pointed by a const char* being updated by a char array that should just hold a copy of the original string literal that should be stored in the ROM.

I know the basic theory of const char*, char* const, const char* const from this link const char * const versus const char *?

#include <stdio.h>
#include <stdlib.h>

int main(){

    char a[] = "ABCD";
    char z[] = "WXYZ";
    const char* b = a;
    a[1] = 'N';  // WHY THIS WORKS AND UPDATES THE VALUE IN B.... a should make its own copy of ABCD and update
                 // it to NBCD... b should still point to a read only memory ABCD which can't be changed4

    //b[1] = 'N'; // THIS FAILS AS DESIRED
    printf("%sn", b);   // Output -> ANCD

    return 0;

Source: c#

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.