Originally Posted by
pdkx7
Thanks ventolin, is there any way to do this with pointers?
There's really no need to do it with pointers if all you need is the value. If, on the other hand, you want changes made to the passed object to be reflected in the original object, you need to use pointers to simulate passing by reference:
Code:
#include <stdio.h>
void foo(int *p);
int
main(void)
{
int i = 0;
printf("In main: %d\n", i);
foo(&i);
printf("In main: %d\n", i);
return 0;
}
void
foo(
int *p
)
{
printf("In foo: %d\n", ++(*p));
}