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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:04:30+00:00 2026-06-03T01:04:30+00:00

I want to declare a pointer to an integer array in the header file

  • 0

I want to declare a pointer to an integer array in the header file for my class. I have

private:
 int *theName;

and then in the constructor

theName = new int[10];

will this work? Is there another way to do this so you have a pointer to an array?

I thought int *theName created a pointer to an integer not an integer array, if this creates a pointer to an integer array how do you create a pointer to just an integer?

Also in the destructor can I call

delete theName; theName = NULL;

Will that delete theName integer array object and then point theName to null in memory?

Thanks

  • 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-03T01:04:31+00:00Added an answer on June 3, 2026 at 1:04 am

    Four things:

    • One, yes that is how you make a pointer to an array. Notice that there’s no difference between a pointer to an integer and a pointer to an integer array; you can think of an integer as an array of one element. You can still use x[0] if x is a pointer to an integer, and you can still use *x if x is a pointer to an array, and they work the same.

    • Secondly, you have to use delete[] theName, not delete theName. Wherever you use new you have to use delete, and wherever you use new[] you have to use delete[]. Also, it is unnecessary to set theName = NULL because after the destructor is run, you can’t access theName any more anyway.

    • Thirdly, when you write a class that manages resources, you need to write a copy constructor, move constructor, copy assignment operator and move assignment operator.

    • Fourthly, unless you are just doing this as a didactic exercise, you should really use std::vector. It has many advantages and no real disadvantages. And you don’t even have to write the four other constructors if you use vector.

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

Sidebar

Related Questions

I have a class which takes two arguments on it's constructor, an int and
I can: declare @idOrder int set @idOrder = 21319 I want: declare @idOrder int
I want to declare three properties in my MSBuild file and overwrite one property
I want to declare a vector in my .h file but depending on the
I want to declare an array of handel as the following code: using namespace
Suppose I have a constant defined in a header file #define THIS_CONST 'A' I
I want to const declare the this pointer received as an argument. static void
I want to declare an object in java that is like a a pointer
Want to verify that my understanding of how this works. Have a C++ Class
I declare an array of structs and want to declare a second into which

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.