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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:06:18+00:00 2026-06-13T19:06:18+00:00

As I read here: http://www.cplusplus.com/reference/stl/array/operator[]/ it appears that saying a[2] would return the memory

  • 0

As I read here: http://www.cplusplus.com/reference/stl/array/operator%5B%5D/

it appears that saying a[2] would return the memory address (a reference) of the second element of a.

So how is

a[2]=5

a valid assignment, as that would mean I change the memory address of a[2] to location 5 (that might be possible, but usually you want to change the value, not the address) . Unless the = operator knows how to deal with this situation.

I know that it doesn’t change the memory address, so what’s actually going on here?

  • 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-06-13T19:06:19+00:00Added an answer on June 13, 2026 at 7:06 pm

    The difference between a reference and a pointer is that a reference is dereferenced automagically. Hence you don’t need such things as *(a[2]) = 5.

    The following code shows this:

    int baseVar = 42;            // This
    int &sameVar = baseVar;      //   and this are the same memory
                                 //   with two different names.
    int *pBaseVar = &baseVar;    // This is separate memory that happens
                                 //   to point to the baseVar memory.
    

    Changing either of sameVar or *pBaseVar will change baseVar itself. Changing pBasevar itself will not affect basevar, it will simply cause to former to point to a different location.

    Under the covers (though this is, of course, implementation dependent, basevar is probably considered (by the compiler/code) to be the int at a specific address (let’s say 0x12345678), sameVar is considered that, too.

    pBaseVar is considered a pointer at (for example) 0x11112222 which happens to contain the value 0x12345678:

                          +------------+
    pBaseVar (0x11112222) | 0x12345678 |--+
                          +------------+  |
       +----------------------------------+
       |
       V                  +----+
    baseVar (0x12345678)  | 42 |
    sameVar (same)        |    |
                          +----+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here http://www.cplusplus.com/reference/stl/set/ I read that std::set in C++ is typically implemented as a tree
I read this article here http://www.codeproject.com/KB/web-security/RolesFormsAuthorization.aspx What is the limitation of Membership that would
I read here: http://www.androidguys.com/2009/10/11/developers-can-now-target-by-carrier-in-android-market/ that it can be done if you go to the
I read here http://www.daniweb.com/code/snippet217293.html# it is possible. What should be activated in PHP.Ini or
Ok, so I've read the tutorial here: http://www.powercram.com/2009/07/connecting-to-aws-ec2-instance-linux.html I created a keypair on Ec2,
I wanted to try the example here http://www.codeconscious.com/rebol/rebol-net.html#HTTP print read/custom http://babelfish.altavista.com/translate.dyn reduce ['POST {text=REBOL+Rules&lp=en_fr}]
Possible Duplicate: What are the differences between struct and class in C++ http://www.cplusplus.com/reference/std/typeinfo/type_info/ I
I have read here http://www.microsoft.com/downloads/en/details.aspx?FamilyID=5765d7a8-7722-4888-a970-ac39b33fd8ab that to instal .NET 4.0 CP (client profile) you
I read from here: http://www.dotnetjohn.com/articles.aspx?articleid=287 the Controller represents the application's business logic. The Model
although I read through the manual here: http://www.doctrine-project.org/documentation/manual/1_2/hu/hierarchical-data I couldn't find a way to

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.