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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:33:08+00:00 2026-06-12T12:33:08+00:00

I found a function to resize an array and am having trouble understanding how

  • 0

I found a function to resize an array and am having trouble understanding how it works (or if it’s working properly). For testing I set the “temp” array to a new value and “startCounter” does get assigned to that value, however the memory location for startCounter doesn’t change. Here is my code:

int * startCounter;


void resizeArray(int *&arraySent,int origSize,int newSize) {
    output << "&arraySent " << &arraySent << endl;
    output << "arraySent[0] " << arraySent[0] << endl;
    int* temp = new int[newSize];
    output << "&temp " << &temp << endl;
    for (int i=0; i<origSize; i++) {
        temp[i] = arraySent[i];
    }
    temp[0]=744;
    delete [] arraySent;
    arraySent = temp;
    output << "&arraySent " << &arraySent << endl;
}

//....

startCounter = new int [3];
startCounter[0]=345;
output << &startCounter << endl;
resizeArray(startCounter,3,10);
output << "startCounter[0]" << startCounter[0] << endl;
output << "&startCounter" << &startCounter << endl;

Here is the output I get from this:

    &startCounter 0x60fab8
    &arraySent 0x60fab8
    arraySent[0] 345
    &temp 0x82cfe54
    &arraySent 0x60fab8
    startCounter[0] 744
    &startCounter 0x60fab8

My question is, why does the memory location of startCounter not change from 0x60fab8 after deleting it and assigning it to the new “temp” array? Shouldn’t it now become 0x82cfe54?

P.S. I understand about vectors and such but am mainly concerned with understanding how this particular function works.

  • 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-12T12:33:09+00:00Added an answer on June 12, 2026 at 12:33 pm
    void resizeArray(int *&arraySent,int origSize,int newSize) {
        output << "&arraySent " << &arraySent << endl;
    

    outputs the address of the pointer variable, not the address that it holds.

    simply omit the address operator to get the (probably) intended effect

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

Sidebar

Related Questions

Working with an undisclosed API, I found a function that can set the number
I used a javascript resize function i found on stackoverflow and it works great
I found a function on the web that generates all sub-multisets of a set
Having a bit of a mental block. I am sure I found a function
I used the following function I found online and it works perfectly. However, when
I'm having some trouble catering for the new iPhone 5 screen height, I need
I'm trying to set up a resize function to my images' onloads so that
recently I found a function like this in a generic JSR245 portlet class: public
I'm reading some third party Verilog, and found this: function [31:0] factorial; input [3:0]
How to move custom marker to front on google map? I found moveToTop function

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.