CMSC 201

Lab 5: Functions

How do I use them?

To call a function just type its name.


This will run whatever code is inside of myFirstFunction()

myFirstFunction()


If the function expects parameters you just put them in the parentheses
mySecondFunction(4, 5)


You can also use variables for the parameters
mySecondFunction(num1, num2)


If your function returns something you can store it in a variable
sum = getSum(13, 4)


If your function returns multiple values you can store them in multiple variables
row, col = getCoordinates(matrix)