Course Content
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.
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:
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:
main.cpp
The typedef
is also applicable:
main.cpp
If you can't exactly specify the return type, the auto
operator will force the compiler to do it for you:
main.cpp
Section 5.
Chapter 2