Type of FunctionsType of Functions

When creating a function, its data type is always specified. That is, what kind of information the function will return after the end of its work.

In the example of the main function, we see that it has an integer data type, which means that after it finishes its work, it will return an integer value, in our case, the number 0.

Note

Since the main function is reserved in C++, it will always be an integer.

But our functions can return any value:

That is, the data type of a function is the data type of the value that the function return.

To call a function, you need to write its name with brackets:

For example:

cpp

main.cpp

We have created a function that returns a value of 3.14 as a double data type, and we have called this function to display its output on the screen.

Functions can also be string type:

cpp

main.cpp

The typedef is also applicable:

cpp

main.cpp

If you can't exactly specify the return type, the auto operator will force the compiler to do it for you:

cpp

main.cpp

Everything was clear?

Section 5. Chapter 2