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 -

java - Jtable duplicate Rows -

java - Run a .jar on Heroku -