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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:32:07+00:00 2026-06-15T04:32:07+00:00

i’m working in VC++, but this is a basic C++ question … I am

  • 0

i’m working in VC++, but this is a basic C++ question … I am quite new with C++, never had to worry about deleting in Java … Anyway, after some research, I believe I have found the right way to do a detele, but does not work … I am using some temporary 2D arrays in a function, and before ending the function, I need to delete them. Here is the code:

int** a;
a = new int*[b/2];
for(int i = 0; i < (b/2); i++)
{
    a[i] = new int[b];

}

    // some code here. Not changing the b variable!

for(int i = 0; i < (b/2); i++)
{
    // error happens here
    delete[] a[i];
}
delete[] a;

After running the programm, I get a “HEAP CORRUPTION DETECTED” error – pasting the printscreen:
Error Printscreen

Any idea where could the problem be?

Thank you.


UPDATE

I am posting the debugger screenshot, happeng just before I get the error. (the variable a’s real name is “vkljucenost”:

Debugger Screenshot


UPDATE

Since some asked me to post more code, I am posting the whole function code:

int** CVaja3KruskalView::CalcKruskal(EnosSez* seznam, int dimenzijaMatr)
{
    int** rezultat; // results array
    int stRezultatov = 0; // number of connections
    rezultat = new int*[dimenzijaMatr-1];
    for(int i = 0; i < (dimenzijaMatr-1); i++)
    {
        rezultat[i] = new int[2]; // shranjujem p in q
        rezultat[i][0] = -1;
        rezultat[i][1] = -1;
    }

    int** vkljucenost;
    int* dolzVkljuc = new int[dimenzijaMatr/2]; // last list elements
    vkljucenost = new int*[dimenzijaMatr/2];
    for(int i = 0; i < (dimenzijaMatr/2); i++)
    {
        vkljucenost[i] = new int[dimenzijaMatr];
        dolzVkljuc[i] = -1; // the i-list is empty
    }

    EnosSez* tmp = seznam;
    int pVkljuc;
    int qVkljuc;
    while(tmp!=NULL)
    {
        pVkljuc=Vkljuceno(vkljucenost, dolzVkljuc, tmp->p, dimenzijaMatr);
        qVkljuc=Vkljuceno(vkljucenost, dolzVkljuc, tmp->q, dimenzijaMatr);

        if(pVkljuc==qVkljuc && pVkljuc != -1) 
        {} else if (pVkljuc!=qVkljuc && pVkljuc != -1 && qVkljuc != -1) 
            rezultat[stRezultatov][0] = tmp->p;
            rezultat[stRezultatov][1] = tmp->q;
            stRezultatov++;

            int prvi = min(pVkljuc,qVkljuc);
            int drugi = max(pVkljuc,qVkljuc);
            // prestavimo drugi seznam v prvega (seznama združimo)
            for(int i = 0; i <= dolzVkljuc[drugi]; i++)
            {
                vkljucenost[prvi][dolzVkljuc[prvi]] = vkljucenost[drugi][i];
                dolzVkljuc[prvi]++;
            }
            dolzVkljuc[drugi] = -1; // spraznemo drugi seznam
        } else if((pVkljuc != -1 && qVkljuc == -1) || (pVkljuc == -1 && qVkljuc != -1)) 
        {
            rezultat[stRezultatov][0] = tmp->p;
            rezultat[stRezultatov][1] = tmp->q;
            stRezultatov++;

            if(pVkljuc == -1)
            {
                vkljucenost[qVkljuc][dolzVkljuc[qVkljuc]] = tmp->p;
                dolzVkljuc[qVkljuc]++;
            } else
            {
                vkljucenost[pVkljuc][dolzVkljuc[pVkljuc]] = tmp->q;
                dolzVkljuc[pVkljuc]++;
            }
        } else 
        {
            rezultat[stRezultatov][0] = tmp->p;
            rezultat[stRezultatov][1] = tmp->q;
            stRezultatov++;

            int prviPrazen = 0; 
            while(dolzVkljuc[prviPrazen] > -1)
            {
                prviPrazen++;
            }
            dolzVkljuc[prviPrazen] = 2;
            vkljucenost[prviPrazen][0]=tmp->p;
            vkljucenost[prviPrazen][1]=tmp->q;
        }


        tmp=tmp->next;
    }

    //destruction
    delete[] dolzVkljuc;
    for(int i = 0; i < (dimenzijaMatr/2); i++)
    {
        // error happening here!!!
        delete[] vkljucenost[i];
    }
    delete[] vkljucenost;

    return rezultat;
}
  • 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-15T04:32:08+00:00Added an answer on June 15, 2026 at 4:32 am

    As suggested in the comments, the problem was in other code, notwith deleting the nodes. I did not debug the code, but, as the commenters suggested, used std::vector instead of array – first checking that the use of vector has in fact the same efficiency as using arrays.

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

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.