Commit 390a738f authored by Alexander Hirsch's avatar Alexander Hirsch
Browse files

Fix call-by-value section

parent 3cc1d691
......@@ -220,10 +220,33 @@ Even further, one cannot assign to a variable of array type.
#### Call by Value / Call by Reference
`bool`, `int`, and `float` are passed directly (by value).
Strings and arrays are passed via pointers internally (by reference).
`bool`, `int`, and `float` are passed by value.
For arrays and strings a pointer is passed by value (similar to C).
Modifications made to an array inside a function are visible outside of that function.
Modifications made to an array inside a function are visible outside the function.
void foo(int[5] arr) {
arr[2] = 42;
}
void main() {
int[5] arr;
foo(arr);
print_int(arr[2]); // outputs 42
}
While strings can be re-assigned (in contrast to arrays), this is not visible outside the function call.
void foo(string s) {
s = "foo";
}
void main() {
string s;
s = "bar";
foo(s);
print(s); // outputs bar
}
#### Type Conversion
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment