Possible Duplicate:
What is the difference between char s[] and char *s in C?
Question about pointers and strings in C
I’m reading about the strings in C and I’m confused. I can “declare” strings in two ways:
char *str = "This is string";
char str2[20] = "This is string";
What is the difference between the two declarations? When would char str2[20] be preferred over char *str?
Puts the string in the
constant data section (also known as .rdata)of the program.This data can’t be modified.In this type of declaration data is preferably
stored in the stack areaof the program, if declared inside thefunction scopeand indata sectionif declared inglobal scope.This data can be modified.So if you have a necessity to modify data then use the second approach.