Suppose I need a function which generates an array r[3] = {x, y, z} where x[1000], y[1000], z[1000] each one is an array and has 1000 double float points. I made a function which returns the location of r form where we need to access the x, y,z by unpacking the memory location. I have the code like:
double cylinder(double radius, double height)
{
double x[1000], y[1000], z[1000];
double theta = 0, dtheta = M_PI / 500, dz = height / 1000;
z[0] = 0;
y[0] = 0;
x[0] = radius;
for (int i = 1; i < 1000; i++)
{
z[i] = z[i - 1] + dz;
theta = theta + dtheta;
x[i] = radius * cos(theta);
y[i] = radius * sin(theta);
}
double * r[3] = {x,y,z};
return **r;
}
now if I use
data = cylinder(5, 10);
cout<<data<<endl;
It should return a location but why it returns 5. I need to have the location of 'data' and from that I will get 3 more memory locations which 3 has all the 1000 points on each location. I will be very thankful to get the solution.