1. ## Passing Structure Pointer

I am having trouble passing this structure with pointers. Im using recursion to implement a marching cubes algorithm. When surrounding cubes is called, it checks each cube on each of the six faces of the cube to see if they have any matching vertices (meaning they are connected). If this is true, surrounding cubes is called again on that cube and so forth. The function checkCube checks if the cube has matching vertices and is in range as well as creates a GRIDCELL(cube) structure with the given data. Im having trouble with the pointers though. It all compiles correctly but whenever it finds a cube its vertices are all wrong. They are correct in checkCube but when it gets back into surrounding cubes they are all 0. I think I am just using the wrong syntax to pass the GRIDCELL structure.

Basically I want to be in surroundingCubes, call checkCube and return a GRIDCELL structure that can be used in another function call.

I only attached code I thought was relevant as the program is already 1000 lines so hopefully this is enough information.

Thanks!

Code:
```typedef struct {
XYZ p[8];
double val[8];
} GRIDCELL;

static void surroundingCubes(GRIDCELL cube, int w, int t, int *flags)
{
int ntri;
int index;
GRIDCELL *grid= (GRIDCELL*)malloc(sizeof(GRIDCELL));

if (checkCube(giCubeLength, (cube.p[1].x) + (giCubeLength-1), cube.p[1].y, cube.p[1].z, t, w, *grid)==true)
{
surroundingCubes(*grid, w, t, flags);
}
...
...
...
}

static bool checkCube (int cubeLength, int startX, int startY, int startZ, int t, int w, GRIDCELL grid)```

2. Do you expect that last parameter to checkCube to change when you call the function? Why? (Hint: functions in C can never modify the actual parameters passed to them such that the calling function can notice.)

3. i thought because it was a pointer it could be modified. it works because the values are correct if I printf the values before i call surrounding cubes but once it gets into surrounding cubes all the values are reset at zero.

4. The last argument to checkCube is just a plain old GRIDCELL, no pointer involved.