c - Where is a char-pointing string stored LOGICALLY? -
in c, can use char * point @ string. like
char *s = "hello";
.
as seen, neither variable located dynamically on heap because there no dynamical functions malloc, nor defined point other variable.
so question is, where literal string variable [char *s] points stored logically?
is stored in stack normal local variables? or, stack?
actually, graduate of computer engineering department, haven't found , have been curious how [char * string] works logically. great honor ask right 1 now.
the variable char* s
stored on stack, assuming it's declared in function body. if declared in class, stored wherever object class stored. if declared global, stored in global memory.
in fact, non-static
, non-thread_local
variable declare in these 3 positions behave same way, regardless of whether primitive (i.e. int
), object (i.e. vector<int>
), or pointer (i.e. const char*
). if variable static, stored in global space. if variable thread_local
, each thread gets own copy, , copy stored @ base of stack corresponding thread.
the actual string "hello"
, s
points to, stored in constant global space somewhere, .data
segment.
Comments
Post a Comment