Functions are generally code blocks that carry out certain instructions in an application. This code block can be called more than once during the application's run time or execution time if its functions are reusable.
ref
functions?ref
functions are functions that return by reference. This is similar to the arguments of the ref
function. For a better understanding, let's look at an example:
import std.stdio;ref int lesser(ref int val1, ref int val2) {return val1;}void main() {int x = 1;int y = 2;lesser(x, y) += 10;writefln("x: %s, y: %s", x, y);}
In the example above, we add 10
to val1
returned from the function.
ref
keyword and its use in the arguments also.val1
to demonstrate the ref
function.ref
function. Here, we use it as a variable. We add 10
to val1
since we only return val1
from the ref
function.