[C言語] const修飾子

int main( void )
{
	char s1[] = "abc";
    char s2[] = "xyz";
    char *s3 = "ABC";

    char *p = s1;
    printf("[1]p=%s\n", p);

    p = s2;
    printf("[2]p=%s\n", p);

    *p = '1';
    printf("[3]p=%s\n", p);

    p = s3;
    printf("[4]p=%s\n", p);

	return 0;
}

$ gcc main.c -o main -lm && ./main
[1]p=abc
[2]p=xyz
[3]p=1yz
[4]p=ABC

*p=1 とすると、1yzとなるのか…

### const char*

int main( void )
{
	const char s1[] = "abc";
    const char s2[] = "xyz";

    const char *p = s1;
    printf("[1]p=%s\n", p);

    p = s2;
    printf("[2]p=%s\n", p);

	return 0;
}

$ gcc main.c -o main -lm && ./main
[1]p=abc
[2]p=xyz

int main( void )
{
	char s1[] = "abc";
    char s2[] = "xyz";

    char *const p = s1;
    printf("[1]p=%s\n", p);

    *p = '1';
    printf("[2]p=%s\n", p);

	return 0;
}

$ gcc main.c -o main -lm && ./main
[1]p=abc
[2]p=1bc