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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:45:28+00:00 2026-05-20T20:45:28+00:00

I have problem in getting wrong values in array of double. Instead of getting

  • 0

I have problem in getting wrong values in array of double.

Instead of getting the values that I’d like to have in “printf” after defining the array’s values one by one, I got 0 instead

 const int M=20;
 const int K=2;
 typedef double polybasis[M][K+1][K+1];
 polybasis Phik;
 for(i=1; i <= M; i++){                     
    for (j=1; j <= K+1; j++){           
        for (k=0; k <= K+1; k++) {a0[k]=0.0;}
        a0[1]=1.000;
        a1=0.000;
        for (k=1; k <= K; k++){
            it=ind[k];
            for (l=1; l <= k+1; l++){
                a2 = a0[l];
                a0[l]= a1-(x[i][it])*a2;
                a1=a2;
            }
        }
        for (k=0; k <= K+1; k++) {ind[k]=0;}
        for (m=0; m <= K+1; m++) {
            Phik[i][j][m]=a0[m]; 
            Phik[i][j][m]=tmp*Phik[i][j][m];
            printf("Phi %i %i %i : %7.8f ; ao : %7.8f \n",i,j,m,Phik[i][j][m],a0[m]);
            //This is where I define the values that I need
        }
    }
}
//But in the end of the iteration, I got 0 values instead for every Phik[_][_][3]
//except the last one: Phik[20][3][3], from this test
printf("phi : %7.8f; \n",Phik[20][2][0]); 
printf("phi : %7.8f; \n",Phik[20][2][1]); 
printf("phi : %7.8f; \n",Phik[20][2][2]); 
printf("phi : %7.8f; \n",Phik[20][2][3]); 

I’m still new to C++, so I don’t know anything about memory leaks. I know that it’s better to use pointer to avoid this, but I need to use typedef for further steps.

Thanks for your help 🙂

  • 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-20T20:45:29+00:00Added an answer on May 20, 2026 at 8:45 pm

    C++ array indices are zero-based. The index must always be less than the extent of the array. For example, your first three loops should probably be:

    for(i=0; i < M; i++){                     
        for (j=0; j <= K; j++){           
            for (k=0; k <= K; k++)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem regarding getting the path of a user control. The scenario
I have problem in some JavaScript that I am writing where the Switch statement
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have a script that appends some rows to a table. One of the
I have an array inside an array and I'd like to simply print out
I'm having a problem getting TryParse to work correctly for me. I have a
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem when I try insert some data to Informix TEXT column via

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.