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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:51:49+00:00 2026-06-06T23:51:49+00:00

Suppose a structure defined as below is allocated dynamically in an array. Would the

  • 0

Suppose a structure defined as below is allocated dynamically in an array. Would the type, label and description need to null terminated in order to safely delete the allocated structures?

struct operation_data
{
    int number;             
    char* type;             
    char* label;                
    char* description;
}

operation *data=new operation_data[5];  
for (int i=0; i<5; i++)
{
    data[i].type=new char[250];
    data[i].label=new char[250];
    data[i].description=new char[250];
}    
for (int i=0; i<5; i++)
{
    if (data[i].type) delete[] data[i].type;
    if (data[i].label) delete[] data[i].label;
    if (data[i].description) delete[] data[i].description;    
}

My code represents the snippet above. this is causing a Heap corruption detected error in the second delete statement. Please help me rectify this.

  • 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-06T23:51:50+00:00Added an answer on June 6, 2026 at 11:51 pm

    no, they dont need to be null terminated. null termination is only an indicator where the string inside the char array ends.

    i would recommend to add a ctor and dtor to your struct to safely delete it.

    struct operation {
      int number;
      char* type;
      char* label;
      char* description;
    
      operation() : type(0), label(0), description(0) {}
      ~operation() {
        if( type )
              delete[] type;
        if( label )
          delete[] label;
        if( description )
          delete[] description;
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have to related structures defined in 2 header files like below: a.h
suppose my table structure is like ID OEReference --- ------------ 1 00000634B9 2 00000634B6
Suppose I have a doc structure like this: thing: { name: { first: John,
Suppose the following object structure: class Super {} class SubA extends Super {} class
Suppose I have a structure in C++ containing a name and a number, e.g.
suppose you have the following structure: #include <windows.h> // BOOL is here. #include <stdio.h>
Suppose I have a structure in C or C++, such as: struct ConfigurableElement {
Suppose i have this structure of elements: <div class=parent> <div class=something1> <div class=something2> <div
Suppose I have the following directory structure in Vim's NERDTree: /some/folder/ |-apples.txt |-bananas.txt |-
Suppose I have the following (desired) folder structure: *CommonProject *Project#1 ----> CommonProject(link) *Project#2 ---->

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.