What is Function in C++?
It is strongly recommended to finish Introduction to C++ course before starting this one. Go here if needed.
In C++, a function is a block of code that performs a specific task. You're familiar with this concept and have used it with the main()
function, which is special in C++ as it marks the starting point for a program. However, using functions in C++ is not limited to just the main()
function. Here's an example:
main.cpp
Let's clarify what was done in the code above:
- We created
calculateFactorial()
function that calculates the factorial of the given number and returns it as an output. - We called this function in our program's
main()
function and printed the result into the console.
You might not get what happened yet – like how we made the function, what stuff we put into it, and what's inside the code. But don't worry, we'll explain it all soon.
Tudo estava claro?
Conteúdo do Curso
C++ Functions
2. Function Arguments Specification
3. Function Return Values Specification
4. Some Advanced Topics
C++ Functions
What is Function in C++?
It is strongly recommended to finish Introduction to C++ course before starting this one. Go here if needed.
In C++, a function is a block of code that performs a specific task. You're familiar with this concept and have used it with the main()
function, which is special in C++ as it marks the starting point for a program. However, using functions in C++ is not limited to just the main()
function. Here's an example:
main.cpp
Let's clarify what was done in the code above:
- We created
calculateFactorial()
function that calculates the factorial of the given number and returns it as an output. - We called this function in our program's
main()
function and printed the result into the console.
You might not get what happened yet – like how we made the function, what stuff we put into it, and what's inside the code. But don't worry, we'll explain it all soon.
Tudo estava claro?