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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:06:34+00:00 2026-05-13T14:06:34+00:00

I have a struct of type Duplicate I have a variable of type int

  • 0

I have a struct of type Duplicate
I have a variable of type int called stringSize, it has a value of 5
I am creating a dynamic array:

Duplicate *duplicates;
duplicates = new Duplicate[stringSize - 1];

Later I delete[] duplicates;

I’m getting one member in that array only? I’ve verified that stringSize – 1 = 4 with a debug walk through. What can I do to get the 4 members I need?

Any help appreciated,
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-05-13T14:06:34+00:00Added an answer on May 13, 2026 at 2:06 pm
    Duplicate *duplicates;
    duplicates = new Duplicate[stringSize - 1];
    

    Indeed gives you duplicates[0-3] (Assuming stringSize - 1 is 4, like you say). How are you determining you’re getting less?

    I suspect you may be doing something like: sizeof(duplicates) / sizeof(duplicates[0]), and on an off-change getting one. The above code only works for statically allocated arrays, where sizeof(duplicates) would match the size of the array, in bytes. In your case, it’ll simply return the size of a pointer on your system. (duplicates is a Duplicate*)

    And mandatory: Use std::vector if this is “real” code.


    Your debugger is doing the best it can. As far is it’s concerned, you’ve merely got a pointer to some data. Consider:

    Duplicate foo;
    Duplicate *duplicates_A;
    duplicates_A = &foo; // points to one Duplicate
    
    Duplicate *duplicates_B;
    duplicates_B = new Duplicate[4]; // points to memory containing 4 Duplicate's
    
    bar(duplicates_A);
    bar(duplicates_B);
    
    void bar(Duplicate* p)
    {
        // is p a pointer to one value, or is it an array?
        // we can't tell, and this is the same boat your debugger is in
    }
    

    How should the debugger, just given a pointer, know if it’s pointing to an array or just one value? It cannot, safely. (It would have to determine, somehow, if the pointer was to an array, and the size of that array.)

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

Sidebar

Related Questions

In .NET, a value type (C# struct ) can't have a constructor with no
Say I have a struct s with an int pointer member variable i. I
I have a type which I consider use it as struct. It represents single
I have this struct: struct Map { public int Size; public Map ( int
Is it possible in C# to have a Struct with a member variable which
I have a struct defined like follows as part of an object. I'm trying
I have a struct like this: class Items { private: struct item { unsigned
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
I have a c# struct where I need to forbid calling the no args
I have a structure: struct pkt_ { double x; double y; double alfa; double

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.