Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1045649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:01:03+00:00 2026-05-16T16:01:03+00:00

Can you do this? char* func() { char * c = String; return c;

  • 0

Can you do this?

char* func()
{
   char * c = "String";
   return c;
}

is “String” here a globally allocated data by compiler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:01:04+00:00Added an answer on May 16, 2026 at 4:01 pm

    You can do that. But it would be even more correct to say:

    const char* func(){
      return "String";
    }
    

    The c++ spec says that string literals are given static storage duration. I can’t link to it because there are precious few versions of the c++ spec online.
    This page on const correctness is the best reference I can find.

    Section 2.13.4 of ISO/IEC 14882 (Programming languages – C++) says:

    1. A string literal is a sequence of characters (as defined in 2.13.2) surrounded by double quotes, optionally
      beginning with the letter L, as in “…” or L”…”. A string literal that does not begin with L is an ordinary
      string literal, also referred to as a narrow string literal. An ordinary string literal has type “array of n
      const char” and static storage duration (3.7), where n is the size of the string as defined below, and is
      initialized with the given characters. …

    2. Whether all string literals are distinct (that is, are stored in nonoverlapping objects) is implementation defined.
      The effect of attempting to modify a string literal is undefined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to return an empty char* , I can do this char*
How can i delete a html-special char \ from a string. $string = 'This
How can I use sed to replace this line char * path_list_[1] = {
If a constant is declared like this const char *http_range; Then how can I
How can I make this print properly without using two printf calls? char* second
hi can anybody tell me the error in this? #include<stdio.h> int main() { char
How can I template these functions? boost::function< void(int) > binder( void(*func)(int, char), int a1,
I have a character pointer like this char *ptr; I can allocate values to
TO_CHAR(( TO_DATE(calendar_key,'YYYYMMDD' )+ 1),'IW') week Can somebody tell me what's happening in this query?
Can this MS-Access query be improved? i.e. the SELECT TOP 1 col FROM Table2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.