c - Character array Assignment -
this question has answer here:
- assigning strings arrays of characters 8 answers
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
Post a Comment