difference between char *s and char s[ ]

The difference here is that :

    char *s = "hello,world!";

will place hello,world in read-only part of the memmory and makes s a pointer to that. making any writing operation on this illigal.

while:

    char s[] = "hello,world!";

will puts the hello,world in read-only memmory and copies the string to newly allocated memmory thus making :

    s[0] = 'j';

legal.

 

from:http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c

posted @ 2015-02-24 21:28  永久指针  阅读(122)  评论(0编辑  收藏  举报