Top Question C passing by reference

A

ademersseman

Guest
I want this function to add a point to the beginning of the linked list:

Mã:
void addPoint(Point *head, int x, int y, SDL_bool dir) {
    Point *p = malloc(sizeof *p);
    p->x = x;
    p->y = y;
    p->dir = dir;
    p->next = head;
    head = p;
}

The head is initialized earlier like so:

Mã:
Point *down = NULL;

Afterwards I call the function like so:

Mã:
addPoint(&down, x * grid_cell_width, (y - 1) * grid_cell_height, SDL_FALSE);

Unfortunately this does not work as After after the call the head is still NULL.

Answer for: "C passing by reference"...
 
Top