I have an array of structures that is dynamically allocated. A pointer to this array is passed to other functions.
struct body{ char* name; double mass;
I need to know the size of the array, so I save the size in one of the structures that is in the 0th element of the array (first structure).
bodies[0].mass = (double)Number_of_bodies;
Then I return from the function a pointer to the 1st element of the array ie bodies[1]
return (bodies+1);
Now, when I use this pointer in other functions, the data should start from the 0th element.
body *new_bodies = (bodies+1); //Just trying to show what happens effectively when i pass to another function new_bodies[0] = *(bodies+1); //I Think
If I want to see the initial structure that was in bodies[0] , does this mean in other functions, do I need to access new_bodies[-1] ?
Can I do something? How can I access the original structure?
Rohan source share