In C++ a program can pass a reference, not value to a function.
void incrementInt(int &x)
{
++x;
}
Does OCaml offer this same functionality?
No, there is no strict equivalent.
There are ref
s, which are like pointers to new-allocated memory, and there are records, arrays, objects and values of other compound data types, that are passed "by object reference", which again means they act like pointer to new-allocated memory.
However there's no equivalent to a pointer to a variable or a C++ reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With