0:00
Hi mates, let's take a look at what functions are and how they work in programming
0:12
A function is a block of code that has a specific task and is executed when being called by
0:17
the calling program. Well, a calling program is a piece of code that can be used to call a function in your
0:25
code in order to execute that function. Talking about types, we have two main types, built-in functions and user-defined functions
0:38
Built-in functions are coded by the language developers and we can use them in our program
0:43
without having to define them, while user-defined functions are defined by us according to our needs
0:51
A function usually has five main components, the return type, function name, arguments
0:59
the body of function, and a returning value. The return type basically specifies what type of value the function will return to a calling
1:10
program, what should be its data type. The function name is what makes the function recognizable
1:18
It is compulsory to set a function name. Arguments are values that a function can accept and can work with it
1:28
They are optional, we can have a function with zero arguments. The body contains one or more lines which defines the function according to our requirement
1:40
The returning value is what a function should be returning to the calling program
1:47
An example from C++ with two arguments. It's returning an integer value
1:56
Function name is sum, taking two integer type arguments and returning its sum in the function body
2:06
The function call is passing five intents as integers and storing its result in variable result
2:15
The five intent will be cached and simply return its sum. By the help of cout object, it will display the result
2:24
A second example is from Python, a function with zero arguments. The function name is welcome underscore message, taking no arguments and it's simply printing
2:38
a welcome message. The calling program is storing the result in message variable and then printing that
2:46
out through the print function. That's all, hopefully it clears your concept about functions
2:55
Thanks for watching, see you soon