Converting C code to Java : <p>Can someone explain to me what the two pieces of code below do, and what the equivalent would look like in Java?</p>

<pre><code>double* ptr;
    ptr = (double*)malloc(10*_R_CONST*sizeof(double)+2048);
</code></pre>

<p>I presumed from my limited knowledge of C that it's declaring a pointer ptr, setting the size of the pointer?</p>

<p>This is what the calls look like later in the same file </p>

<pre><code>ptr[10*n+2]=-RadtoMOA(atan(y/x));
ptr[10*n+0]=x/3;                            
ptr[10*n+1]=y*12;                           
ptr[10*n+2]=-RadtoMOA(atan(y/x));           
ptr[10*n+3]=t+dt;                   
</code></pre>

<hr>

<p>There is another similar function, again I'm unfamiliar with C. The two lines with asterisks are the lines I am wondering about particularly. </p>

<pre><code>double GetRange(double* sln, int yardage){
    **double size=sln[_R_CONST*10+1];**
    if (yardage&lt;size){
        **return sln[10*yardage];**
    }
    else return 0;
}
</code></pre>

<hr>

<p>For the first portion of this question here's the full code, incl. the excerpts above.</p>

<pre><code>double* ptr;
    ptr = (double*)malloc(10*_R_CONST*sizeof(double)+2048);

double t=0;
double dt=0.5/Vi;
double v=0;
double vx=0, vx1=0, vy=0, vy1=0;
double dv=0, dvx=0, dvy=0;
double x=0, y=0;

double headwind=HeadWind(WindSpeed, WindAngle);
double crosswind=CrossWind(WindSpeed, WindAngle);

double Gy=GRAVITY*cos(DegtoRad((Angle + ZAngle)));
double Gx=GRAVITY*sin(DegtoRad((Angle + ZAngle)));

vx=Vi*cos(DegtoRad(ZAngle));
vy=Vi*sin(DegtoRad(ZAngle));

y=-SightHeight/12;

int n=0;
for (t=0;;t=t+dt){

    vx1=vx, vy1=vy; 
    v=pow(pow(vx,2)+pow(vy,2),0.5);
    dt=0.5/v;

    // Compute acceleration using the drag function retardation 
    dv = retard(DragFunction,DragCoefficient,v+headwind);       
    dvx = -(vx/v)*dv;
    dvy = -(vy/v)*dv;

    // Compute velocity, including the resolved gravity vectors.    
    vx=vx + dt*dvx + dt*Gx;
    vy=vy + dt*dvy + dt*Gy;



    if (x/3&gt;=n){
        ptr[10*n+0]=x/3;                            // Range in yds
        ptr[10*n+1]=y*12;                           // Path in inches
        ptr[10*n+2]=-RadtoMOA(atan(y/x));           // Correction in MOA
        ptr[10*n+3]=t+dt;                           // Time in s
        ptr[10*n+4]=Windage(crosswind,Vi,x,t+dt);   // Windage in inches
        ptr[10*n+5]=RadtoMOA(atan(ptr[10*n+4]));    // Windage in MOA
        ptr[10*n+6]=v;                              // Velocity (combined)
        ptr[10*n+7]=vx;                         // Velocity (x)
        ptr[10*n+8]=vy;                         // Velocity (y)
        ptr[10*n+9]=0;                              // Reserved
        n++;    
    }   

    // Compute position based on average velocity.
    x=x+dt*(vx+vx1)/2;
    y=y+dt*(vy+vy1)/2;

    if (fabs(vy)&gt;fabs(3*vx)) break;
    if (n&gt;=R_CONST+1) break;
}

ptr[10*_R_CONST+1]=(double)n;

*Solution = ptr;

return n;
</code></pre>

<p>}</p>
