Click to See Complete Forum and Search --> : Passing pointers in C


tiw
11-20-2000, 12:56 AM
does anyone know how to pass a pointer from a function in C. what i got now is this, will this correctly set test to five?

void function(int *);

int main(){
int * test;
function(test);
printf("%d\n",test);
return 0;
}

void function(int * test){
*test=5;
}

Letalis
11-20-2000, 02:30 AM
Thats correct but you could also do:

void function(int *);

int main(){
int test;
function(&test);
printf("%d\n",test);
return 0;
}

void function(int *test){
*test=5;
}