Lifetime of a const string literal returned by a function

Posted by Neeraj on Stack Overflow See other posts from Stack Overflow or by Neeraj
Published on 2010-04-05T17:32:31Z Indexed on 2010/04/05 18:23 UTC
Read the original article Hit count: 236

Filed under:
|
|

Consider this code:

const char* someFun() {
    // ... some stuff
    return "Some text!!"
}

int main()
{
   { // Block: A
      const char* retStr = someFun();
      // use retStr
   }
}

My question is in the function sumFun() where is "some Text!!", stored (i think may be in some static area in ROM) and what will be its scope?

Will the memory pointed by retStr be occupied throughout the program or be released once the block A exits?

--
Thanks

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++