Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What is Function in C++? | Introduction
C++ Functions

What is Function in C++?What is Function in C++?

Pay attention!

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:

cpp

main.cpp

Let's clarify what was done in the code above:

  1. We created calculateFactorial() function that calculates the factorial of the given number and returns it as an output.
  2. 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.

Are you ready to start learning functions?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 1
course content

Зміст курсу

C++ Functions

What is Function in C++?What is Function in C++?

Pay attention!

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:

cpp

main.cpp

Let's clarify what was done in the code above:

  1. We created calculateFactorial() function that calculates the factorial of the given number and returns it as an output.
  2. 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.

Are you ready to start learning functions?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 1
some-alt