Introduction to Functions

What Is a Function?

A function is a block of code that can be reused. It is used to perform some specific tasks.

  • main Function

    The simplest possible function that we have studied so far is the main function that is declared with fn keyword. This is where the program execution starts.

    However, it is possible to define a user-defined function.

  • User-defined Functions

    The functions that are customized and are written by the programmer to perform the specified tasks.

Define a Function

A function is declared with the fn keyword.

Syntax

The general syntax is :

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy