Pass by reference in C

C does not have references. You need to pass a pointer to the variable you wish to modify:

int locate(char *name, int *s, int *i)
{
    /* ... */

    *s = 123;
    *i = 456;
}

int s = 0;
int i = 0;
locate("GMan", &s, &i);

/* s & i have been modified */

Leave a Comment