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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:06:02+00:00 2026-06-01T16:06:02+00:00

Can some one tell me what is wrong in the for loop? When I

  • 0

Can some one tell me what is wrong in the for loop? When I run it, it interrupts. I tried to debug to see what is wrong, I noticed that in the for loop it just stops:

#define MAX_POPULATION 64
float **tr_pop;//Tournament candidates
float **matingPool;//Mating pool
tr_pop=new float *[m];
matingPool=new float *[m];
for(l=0;l<m+1;l++)//allocating
{
    tr_pop[l]=new float[MAX_POPULATION];
    matingPool[l]=new float[MAX_POPULATION];
}
for ( int r = 0; r < row; ++r )//deleting
{
 delete [] matingPool[r];//Stops here (not ending program just frozen)
 delete [] tr_pop[r];
}
delete [] tr_pop;
delete [] matingPool;

=======OK. PROBLEM SOLVED=======

Here is the reason:

I just changed the MAX_POPULATION into the MAX_POPULATION+1 and it worked.

for(l=0;l<m+1;l++)
    {
    tr_pop[l]=new float[MAX_POPULATION+1];
    matingPool[l]=new float[MAX_POPULATION+1];
    }

Because in another function I think I was doing violation:

void crossover()
{
int p1,p2,i,j;float tempBit;
p1=m/3;
p2=(2*m)/3;
for(j=0;j<MAX_POPULATION;j++)
{
    for(i=p1;i<p2;i++)
    {
    tempBit=matingPool[i][j];
    matingPool[i][j]=matingPool[i][j+1];//THE VIOLATION POINT (I THINK)
    matingPool[i][j+1]=tempBit;
    }
    j++;
}

As you can see, when j = MAX_POPULATION at the end of the loop, i was trying to reach MAX_POPULATION + 1. So I changed the allocations for columns, and the problem solved 🙂

  • 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-01T16:06:04+00:00Added an answer on June 1, 2026 at 4:06 pm

    You’re running into undefined behavior:

    for(l=0;l<m+1;l++)//allocating
    {
        tr_pop[l]=new float[MAX_POPULATION];
    }
    

    should be

    for(l=0;l<m;l++)//allocating
    {
        tr_pop[l]=new float[MAX_POPULATION];
    }
    

    You’re allocating m elements for each of the arrays and try to access m+1.

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

Sidebar

Related Questions

Can some one tell me were i am going wrong. i have three activity's
Hi can some one tell me whats the wrong in the below code? Trying
Can some one tell me how do i display real time in c++. what
Please can some one briefly tell me with example what does the means of
Can someone tell what is wrong with this query? sqltext = SELECT utyp, count(*)
Can someone please tell me whats wrong with this code. I'm not getting complete
Can someone tell me what is wrong with this code? <?php $user = $fgmembersite->UserFullName();
Can someone tell me what is wrong with my code? $c = '<div class=desc>';
Hi can someone tell me what i'm doing wrong in this jquery statement. I
Can someone who is way smarter than I tell me what I'm doing wrong..

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.