xxxxxxxxxx
[0]
A function call is a request made by a program or script that performs a
predetermined function.
[1]
A function call is an important part of the C programming language. It is
called inside a program whenever it is required to call a function. It is only
called by its name in the main() function of a program. We can pass the
parameters to a function calling in the main() function.
[2]
The process of transferring control from one function to another (until the
other function returns) is known as calling a function, or making a function
call.
The function being called is known as the called function, or more concisely,
the callee.
The function that makes the call is known as the calling function, or more
concisely, the caller.
While println is a method, it is a very simple one which only requires passing it an argument which can be of any type. However, most methods require you to call them on something, let’s call that something an object for now. That object can be anything from AnyVal to AnyRef. For example, objectName.method(argument) means that the method is being called on objectName and argument are parameters passed to the method. The method will perform some action on the data stored in objectName.
Most methods allow you to only pass an argument of a specific data type. Let’s call one of Scalas built-in methods, indexOf to get a better idea of how this works.
IndexOf is called on a string and you pass it one argument of type Char. It is used to calculate the index of a character in a string.
xxxxxxxxxx
val string1 = "Hello World"
val result = string1.indexOf('W')
// Driver Code
println(result)
You call a user-defined function the same way you call a built-in function; by calling its name followed by the input in (). Let’s call the sum function we defined above. We will store the return value of the function in a variable result.
xxxxxxxxxx
def sum(x: Int, y: Int): Int ={
x+y
}
val total = sum(2,3)
// Driver Code
println(total)