Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Type of Functions | Introduction to Functions
C++ Introduction

bookType of Functions

When creating a function, the data type of the return value must always be specified. In the main function, the return type is declared as int, indicating that it will return an integer value upon completion. In most cases, the main function returns 0 to signify that the program has successfully executed.

main.cpp

main.cpp

copy
1234
int main() { return 0; }
Note
Note

The main function is reserved in C++ and it always returns an integer. You can omit the return statement only in the main function, as the compiler automatically adds return 0; at the end.

Custom functions can return any value, but it's essential to understand that the type of the return value must match the specified return type in the function definition.

custom_function.h

custom_function.h

copy
123456
// Define a function with a specific return type and name ___ custom_function() { // Return a value that matches the function's return type return ___; }
question mark

What must always match in a function definition and its return statement?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 3.85

bookType of Functions

Swipe to show menu

When creating a function, the data type of the return value must always be specified. In the main function, the return type is declared as int, indicating that it will return an integer value upon completion. In most cases, the main function returns 0 to signify that the program has successfully executed.

main.cpp

main.cpp

copy
1234
int main() { return 0; }
Note
Note

The main function is reserved in C++ and it always returns an integer. You can omit the return statement only in the main function, as the compiler automatically adds return 0; at the end.

Custom functions can return any value, but it's essential to understand that the type of the return value must match the specified return type in the function definition.

custom_function.h

custom_function.h

copy
123456
// Define a function with a specific return type and name ___ custom_function() { // Return a value that matches the function's return type return ___; }
question mark

What must always match in a function definition and its return statement?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 2
some-alt