How to change value of variable passed as argument in C? I tried this:
void foo(char *foo, int baa){
if(baa) {
foo = \"ab\";
} else {
You question is titled in a generic way. You've already got answers for your specific problem. I'm going to add couple of illustrative examples for int
and double
types.
#include
void incrementInt(int* in, int inc)
{
*in += inc;
}
void incrementDouble(double* in, double inc)
{
*in += inc;
}
int main()
{
int i = 10;
double d = 10.2;
printf("i: %d, d: %lf\n", i, d);
incrementInt(&i, 20);
incrementDouble(&d, 9.7);
printf("i: %d, d: %lf\n", i, d);
}
Output:
i: 10, d: 10.200000
i: 30, d: 19.900000