difference between char *s and char s[]
In C, what's the difference between
char *s="Hello"; and char s[]="hello";
The difference here is that
char*s ="Hello";
will place Hello in the read-only parts of the memory and making s a pointer to that, making any writing operation on this memory illegal. While doing:
char s[]="Hello";
puts the literal string in read-only memory and copies the string to newly allocated memory on the stack. Making
s[0]='J';
legal.
Reference:http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c