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 6108163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:16:02+00:00 2026-05-23T14:16:02+00:00

Consider the following code. I’ve included excessive couts for clarity (at least on my

  • 0

Consider the following code. I’ve included excessive couts for clarity (at least on my end):

#include <iostream>

using namespace std;

int main(){
double *array1;    
array1 = new double[10];
array1[5] = 10;

//the following 2 lines return the same thing
cout << "array1 = " << array1 << endl;
cout << "&array1[0] = " << &array1[0] << endl;

double *subarray1;
subarray1 = new double[5];
subarray1 = &array1[5];

//now the following 2 lines return the same thing
cout << array1[5] << endl;
cout << subarray1[0] << endl;

//but I'm not allowed to do:
//&subarray1[0] = &array1[5];

return 0;
}

since

subarray1 == &subarray1[0]

and since I am allowed to do this:

subarray1 = &array1[5];

then why can’t I do this:

&subarray1[0] = &array1[5];

The error that I receive is: warning: target of assignment not really an lvalue; this will be a hard error in the future

  • 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-23T14:16:02+00:00Added an answer on May 23, 2026 at 2:16 pm

    The expression subarray1 is an lvalue to your pointer object of the same name. This pointer points to the first element of the dynamically-allocated buffer.

    The expression &subarray1[0] is an rvalue pointer that points to the first element of the dynamically-allocated buffer (and thus it evaluates to the same value as subarray1).

    These are not the same thing, and you may not assign to an rvalue.

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

Sidebar

Related Questions

please consider following code #include <iostream> using namespace std; class Digit { private: int
Please let us consider following code: #include <iostream> using namespace std; union{ int i;
Consider following example code: #include <iostream> #include <inttypes.h> using namespace std; int f(uint32_t i)
Consider the following code: #include <iostream> struct A { ~A() { std::cout << ~A
Consider the following code: #include <iostream> struct test { void public_test() { [this]() {
Consider the following code snippet: std::vector<int> v; v.reserve(100); v.insert(v.end(), 100, 5); v.erase(v.begin(), v.end()); std::cout
Consider the following code: #include <iostream> #include <cinttypes> template<class T> void f(); template<> inline
Consider the following code : #include <iostream> #include <vector> #include <type_traits> // Version A
Consider the following code : #include <iostream> #include <type_traits> class Base { public: static
Consider following code: main.cpp: #include <iostream> typedef void ( * fncptr)(void); extern void externalfunc(void);

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.