36 lines
848 B
Plaintext
36 lines
848 B
Plaintext
// Calling a function that requires no arguments
|
|
void foo() {puts("Calling a function with no arguments");}
|
|
foo();
|
|
|
|
// Calling a function with a fixed number of arguments
|
|
abs(-36);
|
|
|
|
// Calling a function with optional arguments
|
|
puts(nonewline: "nonewline is an optional argument");
|
|
puts("\n");
|
|
|
|
// Calling a function with a variable number of arguments
|
|
void var_arg_func(...args) {
|
|
puts(length(args));
|
|
}
|
|
var_arg_func(1, 2);
|
|
var_arg_func(1, 2, 3);
|
|
|
|
// Obtaining the return value of a function
|
|
int s = clock("seconds"); //current time in seconds
|
|
// Calling a function with named arguments
|
|
// format is a named argument in Clock_format
|
|
int str = Clock_format(s, format: "%B");
|
|
puts(str);
|
|
|
|
// Stating whether arguments are passed by value or by reference
|
|
void f(int a, int &b) { a++; b++; }
|
|
{
|
|
int a = 0;
|
|
int b = 0;
|
|
|
|
f(a, &b);
|
|
puts (a);
|
|
puts (b);
|
|
}
|