Escolar Documentos
Profissional Documentos
Cultura Documentos
● A small program that can take an input, process the input, and outputs a result.
● Encapsulates a piece of code that can be used by other code. Reduces the repetition in
code.
● Breaks up the program into smaller program or manageable pieces. It is inefficient to
write your code in one go. A project can span for months or even years.
● Functions are mostly actions that you call on demand. This is why functions are named
using verb form.
Parts of Functions
Parameters - input data for
Access Modifier - functions. Separated by
Static - Always write You don’t have to comma for multiple
this for now. We’ll get write this for now. All parameters.
back to this later in the functions are private
course. by default.
● Allows you to write functions with the same name but with different set of parameters.
● This creates different ways to use the function through parameters.
● The compiler can differentiate the functions by reading their function signature.
● Function signature is defined by:
○ Function name
○ Parameter list
○ Return type is NOT included. Be careful.
Function Overloading
Benefits of using Functions
● Code Organization - Break up large complex tasks into smaller and manageable tasks.
○ DO NOT PUT EVERYTHING IN MAIN()
● Code Reuse - Once you’ve written the function, you can call it from anywhere.
○ AVOID COPY PASTING CODE
● Dynamic Input - With the same function, we can supply it with different values for
input.
How do I name my functions?