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
时间: 2024-10-10 08:27:16