return("hello")

R

ranveerkunal

where are string literals stored : data segement, stack
ex.
char *test()
{
return("hello");
}
int main()
{
puts(test());
return 0;
}

where is "hello" literal stored (i)stack of test function (ii)data
segement or somewhere else ...
case (i) should print some garbage.
case (ii) should print hello

it prints hello (linux 2.6/gcc if it matters) ..... explain me.
can anyone explain or give some good link, about what gets stored
where.
 
E

Eric Sosman

where are string literals stored : data segement, stack
ex.
char *test()
{
return("hello");
}
int main()
{
puts(test());
return 0;
}

where is "hello" literal stored (i)stack of test function (ii)data
segement or somewhere else ...
case (i) should print some garbage.
case (ii) should print hello

it prints hello (linux 2.6/gcc if it matters) ..... explain me.
can anyone explain or give some good link, about what gets stored
where.

The anonymous char[] array created by the compiler
resides "somewhere." The "somewhere" might be called a
data segment, a constant pool, a text segment, a magic
wallet, or a mercury delay line -- these are just details
of particular implementations, not part of the language.

No matter where it resides, the array has "static
storage duration," meaning that it comes into existence
some time before main() is called and remains in existence
until the program terminates.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top