course content

Course Content

Introduction to C++

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 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 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

Section 5.

Chapter 2