Introduction to C++
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.
mainfunction 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:
We have created a function of type
double that simply returns a pure
3.14 and called this function to the screen.
The result of our function will be displayed on the screen.
Functions can also be
typedef is also applicable:
If you can't exactly specify the return type, the
auto operator will force the compiler to do it for you: