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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:30:36+00:00 2026-06-11T23:30:36+00:00

So I’m transitioning from Java to C++ and am still having trouble trying to

  • 0

So I’m transitioning from Java to C++ and am still having trouble trying to get my mind wrapped around how pointers work >.< Hope some of you seasoned C++ programmers can help me out!

In class we created both a stack and queue implementation using a dynamic array.

My teacher used pointers to create these arrays on the heap.

int* data = new int[25];

What I don’t understand is how can you insert values into the array with “data[top]”? I thought pointers just held the memory address? I would ask my teacher how this works but I’m on a time crunch and she won’t be able to get back to me till tomorrow afternoon >.<

Stack::push(int value) {
    if(top==size) {
        resize();
    }
    data[top] = value;
    top++;
}
  • 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-11T23:30:37+00:00Added an answer on June 11, 2026 at 11:30 pm

    I thought pointers just held the memory address?

    Yes, but you’re allowed to do things with that memory address. In particular C++ allows something called ‘pointer arithmetic’ which allows you to use a memory address to obtain the address of other memory located relative to the memory you already have the address for. E.g., if you have a memory address you can get the address of the memory located immediately after it.

    (the squares are memory locations)

    ☐
    ☐ 
    ☐  ← I have the address of this memory in variable A
    ☐  ← I would like to get the address of this memory location and to store it in X
    ☐
    ☐
    ☐
    
    
    int *A = ...;
    int *X = A + 1; // compute the address of the next memory location
    

    So an array is a series of memory locations. To access any element of the array you simply take the address you have, compute the address of the element you want to access, and then use that new address.

    int *A = new int[10];
    int *X = A + 5; // get the address of the memory five locations past where A points to
    *X = 999;
    

    You don’t have to store the address you compute in a variable:

    int *A = new int[10];
    *(A+5) = 999;
    

    C++ provides a shorthand for the syntax *(A+5), this is the array index operator:

    int *A = new int[10];
    A[5] = 999;
    

    One thing that’s interesting is that the array index operator really is just shorthand for this *(A+5) expression. Since you can flip around the operands and do *(5+A) you can do the same with the array index operator:

    5[A] = 999;
    

    You shouldn’t do that though, because it’s not very readable.


    Another thing to know about pointers: Java has pointers. When you do

    String s = new String();
    

    in Java s is a pointer. Java just tries to hide this fact at the same time that it requires the use of pointers to a much greater extent than C++ does. Java doesn’t have pointer arithmetic, and you don’t have to manually dereference pointers in Java like you have to in C++. But consider:

    List<String> l = new List<String>();
    List<String> m = l; // Do I have two lists, l and m, that can be modified independently? Or do I have two entities, l and m, that both refer to the same List object?
    

    And remember those Null Pointer exceptions you get in Java.

    If you’ve been using Java then you’ve already been using pointers. They’re not really all that different in C++, but they’re directly visible and explicit in C++ instead of being poorly hidden the way Java has them.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.