c - Character array Assignment -


this question has answer here:

int main() {       char s[]="stack";      s="overflow"; } 

this not allowed.its gives error.but below code works fine.

int main() {       char s[]="stack";       strcpy(s,"overflow"); } 

why happens?

the variable s represents pointer string. more specifically, refers memory address of first letter in string "stack". due reason, operation s="overflow" makes no sense. how can set value of s (a pointer) string?

keep in mind c low-level language, have wary of things might seem intuitive not behaving way expect them to.


Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

python - Received unregistered task using Celery with Django -

php - Retrieving data submitted with Yii's CActiveForm -