I have a piece of code that is written in C++ and need it in C. I converted most of it but I can’t figure out how to convert C++ pass-by-reference in functions to C code, i.e.
Example:
int& a;
it is used in some function as a input variable:
void do_something(float f, char ch, int& a)
When I compile it with C I get compiler errors. Whats the correct way to replace the pass by references in C?
The way to do this in C is to pass by pointer:
Also when using a in
do_somethinginstead ofYou now need to dereference
aAnd when calling
do_somethingyou need to take the address of what’s being passed for a, so instead ofYou need to do:
to get the address of (ie the pointer to) foo.