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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:33:15+00:00 2026-05-23T20:33:15+00:00

My apologies, I know there are a million questions on pointers, arrays etc. although

  • 0

My apologies, I know there are a million questions on pointers, arrays etc. although as basic as this is I just can’t seem to find anything pointing (ha ha!) to an answer.

I’ve got a pointer that is initialised to point to a chunk of memory, I understand that I can access this memory similar to how I would an array:

char *mMem=new char[5000];
cout<<mMem[5]<<endl;

Which is actually:

char *mMem=new char[5000];
cout<<*(mMem+5)<<endl;

What I don’t understand though is how to get the address of an element – I’m aware that element isn’t quite the right word considering mMem isn’t an array – that’s if my understanding is correct, can’t be too sure though because it seems every site uses whatever words it wants when it comes to pointers and arrays. So, if I have:

char *mMem=new char[5000];
cout<<mMem[5]<<endl;
    or
cout<<*(mMem+5)<<endl;

why does the address of operator not work correctly:

cout<<&mMem[5]<<endl;

Instead of getting the address of the 5th element, I get a print out of the memory block contents from that element onwards. So, why did the address of operator not work as I was expecting and how can I get the address of an element of the memory?

  • 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-23T20:33:16+00:00Added an answer on May 23, 2026 at 8:33 pm

    &mMem[5] is the address of the 5th element. The reason why you get a printout of the memory from there is because they type of &mMem[5] is char*, but strings in legacy C are also of char*, so the << operator simply thinks that you want to print a string from there. I would try casting the pointer to a void* before printing:

    cout << static_cast<void*>(&mMem[5]) << endl;
    

    By the way, &mMem[5] and mMem+5 are just the same.

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

Sidebar

Related Questions

Apologies for this seemingly minor question, but I can't seem to find the answer
I know there are lots of FF/Chrome CSS questions, but I can't seem to
Firstly apologies if this a very basic question, I'm just curious to know the
Apologies if this is obvious, I'm new to C++. There seem to be related
Apologies for the open endedness of this question, but I really don't know what
My apologies if this is a duplicate; I may not know the proper terms
My apologies if this is a little broad, but I'm struggling to know where
Apologies is this is something a more seasoned R user would know, but I
Im a novice, apologies up front if this is unclear! I know what I
apologies if this is a duplicate. Is there any way to determine what generic

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.