All:
Would appreciate some help with c ,in particular C18. I want to pass a variable to a function via an argument. The function would modify the value of the variable, BUT I don't want to just modify the variable inside the function, but the original variable itself, if you know what I mean. I believe I need to be using pointers, but lost on them. To simplify what I am trying to achieve consider the following.
Function foo simply accepts a int variable and changes it to 10 then could do some additional changes to variable j. The original variable is declared and then passed as the variable a, but I want the value of variable a to be changed every time the function foo process a change to variable j.??
I think I need to be doing something like this using pointers but it fails to compile.
Would appreciate some help with c ,in particular C18. I want to pass a variable to a function via an argument. The function would modify the value of the variable, BUT I don't want to just modify the variable inside the function, but the original variable itself, if you know what I mean. I believe I need to be using pointers, but lost on them. To simplify what I am trying to achieve consider the following.
Function foo simply accepts a int variable and changes it to 10 then could do some additional changes to variable j. The original variable is declared and then passed as the variable a, but I want the value of variable a to be changed every time the function foo process a change to variable j.??
Code:
void foo(unsigned int j)
{
j=10;
//do something else
//do something else
return;
}
void main()
{
int a=1;
foo(a);
}
I think I need to be doing something like this using pointers but it fails to compile.
Code:
void foo(unsigned int *j)
{
j=10;
//do something else
//do something else
return;
}
void main()
{
int a=1;
foo(&a);
}