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

  • Home
  • SEARCH
  • 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 6836369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:20:50+00:00 2026-05-26T23:20:50+00:00

I’m a bit confused about this: I thought that if a pointer points to

  • 0

I’m a bit confused about this:

I thought that if a pointer points to some object, assigning a dereference to some reference variable was a mere aliasing.

Example:

Object * p = &o;
Object & r = *p;
// r and o are the same object

I was aware there was some illegal cases, like:

Object * p = NULL;
Object & r = *p; // illegal

Now, what about the code below ?

const char * p = "some string";
const char & r = *p;

or

const char & r = *"some string";

I was said that this particular case involved temporary objects and, therefore I could’nt get the address of r and be sure it will point to a memory array containing my initial string.

What does C++ standard states about that case ? Is it another illegal case like the NULL provision, or is it allowed behavior.

In other words, is it legal or illegal (undefined behavior ?) to write something like ?

   char buffer[100];
   strcpy(buffer, &r);
  • 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-26T23:20:50+00:00Added an answer on May 26, 2026 at 11:20 pm

    That’s fine.

    The string literal’s data buffer will exist for the duration of your program (usually in a special segment of the process memory).

    [C++11: 2.14.5/8]: Ordinary string literals and UTF-8 string
    literals are also referred to as narrow string literals. A narrow
    string literal
    has type “array of n const char`”, where n is the size
    of the string as defined below, and has static storage duration (3.7).

    [C++11: 3.7.1/1]: All variables which do not have dynamic storage
    duration, do not have thread storage duration, and are not local have
    static storage duration. The storage for these entities shall last for
    the duration of the program
    (3.6.2, 3.6.3).

    After all, that’s how keeping a pointer to it works! Recall that pointers don’t magically extend object lifetime any more than do references.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.