Contenido del Curso
C++ Introduction
4. Introduction to Program Flow
5. Introduction to Functions
C++ Introduction
Type of Functions
When creating a function, the data type it returns always specified.
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 return integer.
But our functions can return any value:
To call a function, you need to write its name with brackets:
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:
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
¿Todo estuvo claro?
Contenido del Curso
C++ Introduction
4. Introduction to Program Flow
5. Introduction to Functions
C++ Introduction
Type of Functions
When creating a function, the data type it returns always specified.
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 return integer.
But our functions can return any value:
To call a function, you need to write its name with brackets:
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:
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
¿Todo estuvo claro?