Functions are generally code blocks that carry out certain instructions in an application. These code blocks can be called more than once during the application's run time or execution time.
inout
functions?The inout
function is declared using the keyword inout
. It is also able to take in values through parameters and return outputs. In inout
functions, mutability attributes can be transferred to the return type. In these functions, we also transform the parameter data from one type to another before returning. Let's see an example:
import std.stdio;inout(char)[] qoutedWord(inout(char)[] phrase) {return '"' ~ phrase ~ '"';}void main() {immutable(char)[] c = "test c";c = qoutedWord(c);writeln(typeof(qoutedWord(c)).stringof," ", c);}
inout
function. Notice how we use the inout
keyword while declaring the function.inout
function and transform a variable to another type before printing to check the new type in line 12.