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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:29:57+00:00 2026-05-26T19:29:57+00:00

I have filled a dynamic allocated float multi array in a function. A second

  • 0

I have filled a dynamic allocated float multi array in a function.

A second function has to get the values of the array exploiting the pointer to the first element of the array defined in the former function.

The second function do not access to the correct memory location so it doesn’t work but it does if the multy array is defined in a static way.

Does somebody know why?

eval_cell should get values defined in div_int

float f_imp(float x, float y){
     return pow(x,2)+pow(y,2)-1;
}


int eval_cell(float* p){
    int s[4];
    s[0] = f_imp(*p, *(p+1)) <= 0;
    printf("%f %f\n",*p, *(p+1));

    s[1] = f_imp(*(p+3), *(p+4)) <= 0;
    printf("%f %f\n",*(p+3), *(p+4));

    s[2] = f_imp(*(p+9), *(p+10)) <= 0;
    printf("%f %f\n",*(p+9), *(p+10));

    s[3] = f_imp(*(p+6), *(p+7))  <= 0;
    printf("%f %f\n",*(p+6), *(p+7));

    printf("%d%d%d%d\n",s[0],s[1],s[2],s[3]);
    return s[0];
}

void div_int(float* x1, float* y1,float* x2,float* y2,
             float* f0, float* f2,float* f6,float* f8){
    int i,j,m;
    float* p;
    float** a_cell; // array 9x3 contente coordinate vertici e valore funzione
    *a_cell = (float**) malloc(9*sizeof(float*));
    for (i=0;i<9;i++){
       a_cell[i] = (float*) malloc(3*sizeof(float));
    }
    a_cell[0][0] = *x1;
    a_cell[0][1] = *y1;
    a_cell[0][2] = *f0;
    a_cell[2][0] = *x2;
    a_cell[2][1] = *y1;
    a_cell[2][2] = *f2;
    a_cell[6][0] = *x1;
    a_cell[6][1] = *y2;
    a_cell[6][2] = *f6;
    a_cell[8][0] = *x2;
    a_cell[8][1] = *y2;
    a_cell[8][2] = *f8;
/***   calcolo dei valori incogniti di a_cell            ***/
    a_cell[1][0] = (*x1+*x2)/2;
    a_cell[1][1] = *y1;
    a_cell[1][2] = f_imp(a_cell[1][0], a_cell[1][1]);
    a_cell[3][0] = *x1;
    a_cell[3][1] = (*y1+*y2)/2;
    a_cell[3][2] = f_imp(a_cell[3][0], a_cell[3][1]);;
    a_cell[4][0] = (*x2+*x1)/2;
    a_cell[4][1] = (*y2+*y1)/2;
    a_cell[4][2] = f_imp(a_cell[4][0], a_cell[4][1]);
    a_cell[5][0] = *x2;
    a_cell[5][1] = (*y2+*y1)/2;
    a_cell[5][2] = f_imp(a_cell[5][0], a_cell[5][1]);
    a_cell[7][0] = (*x1+*x2)/2;
    a_cell[7][1] = *y2;
    a_cell[7][2] = f_imp(a_cell[7][0], a_cell[7][1]);

    for (j=0;j<2;j++){
       m = j*3;
       for(i=0;i<2;i++){
       m += i;
       eval_cell(&a_cell[m][0]);
       }
    }
    p = *a_cell;
    for (i=0;i<9;i++){
        for (j=0;j<3;j++){
          printf("%f \n",*(p+3*i+j));
          printf("%f \n",a_cell[i][j]);
      printf("\n");
       }
    }
   free(a_cell);
   return;
}
  • 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-26T19:29:58+00:00Added an answer on May 26, 2026 at 7:29 pm

    It’s because you using pointer in incorrect way:
    See a_cell is pointer to dynamic array of 9 pointers to dynamic array of 3 floats.
    So when you do eval_cell(&a_cell[m][0]) (or just eval_cell(a_cell[m]) this is actually the same) you actually get pointer to array of 3 floats. And after that you do:

    int eval_cell(float* p){
    
    ...
    s[2] = f_imp(*(p+9), *(p+10)) <= 0;
    

    *(p+9) will get 9th element in array of 3 floats, so this is incorrect.

    It works in static way, because static multi dimension array in memory is just one dimension array for which you was given multi indexing (by compiler). That’s why in static you will probably address valid memory area.

    See picture for more explanation:
    enter image description here

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

Sidebar

Related Questions

First array list:- ArrayList<Object> list1; Second array list:- ArrayList<Object> list2; Suppose I have filled
I have dynamic array filled with bytes, which are read from .raw file with
I have a few GridItem components that gets filled with dynamic data. Sometimes this
I have a byte array filled from a file uploaded. But, in another part
I have filled an array of this object and I think I'm filling it
I have a ListView that is filled with a dynamic set of data each
I have filled List<Object1> Object 1 contain 2 fields (int id & string name)
i have dropdownlist of year which is coming dynamically.i have filled the dropdownlist using
I have a container filled with pairs. I want to iterate in it using
I have a mysql database filled up and running on a Windows computer, is

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.