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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:21:32+00:00 2026-05-23T21:21:32+00:00

I have created an array of doubles using the following code: double *points =

  • 0

I have created an array of doubles using the following code:

double *points = new double[(ii+1)*(jj+1)*(kk+1)*3];

I realize that in order to delete the array, all I have to do is:

delete[] points;

However; the array is created in a function (called create_points) that passes the address of the first element as follows:

return &points[0];

The code that calls this function then iterates through the address:

double *address = create_points(x_dim,y_dim,z_dim);
for(int k=0; k<x_dim+1; ++k)
    for(int j=0; j<y_dim+1; ++j)
        for(int i=0; i<z_dim+1; ++i) {
            v[p_count].x = *address;
            ++address;
            v[p_count].y = *address;
            ++address;
            v[p_count].z = *address;
            ++address;
            ++p_count;
        }

Now my question is, how do I properly delete the array of doubles that address is used to access? Can I simply go delete[] address, or do I have to do this some other way?

  • 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-23T21:21:32+00:00Added an answer on May 23, 2026 at 9:21 pm

    You cannot say delete[] address, doing so is undefined behavior. You have to delete it through a pointer to the original base address of the array. So, if you’re going to increment the pointer, you need to remember the original pointer (or recompute it):

    double *base_address = create_points(...);
    double *address = base_address;
    // do stuff with address, increment it, etc.
    delete [] base_address
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array created with this code: var widthRange = new Array(); widthRange[46]
I have a very large array of doubles that I am using a disk-based
Explanation I have a multidimensional array that is iterated over to created a categorized
I have created a number objects using an array statement, and I can println
i have the following code and i am receiving the error size of array
i am trying to create a 2d array using double pointer... my code is...
i have created Array of Linkbutton and when user click on link button it
I have created an array Man: public main blah blah{ man = man[10]; }
How do I pass an array I have created on the server side onto
I have an array I've created in JavaScript. The end result comes out 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.