420,179 views
0 votes
0 votes
Which of the following is the default return value of functions in C++?

User Abhishek B Patel
by
3.0k points

1 Answer

18 votes
18 votes

Answer:

In C++, if a function does not specify a return type, the default return type is int. If a function does not return a value, the default return value is undefined.For example, the following function has a default return type of int:

// Default return type is int

void foo()

{

// Do something

}

If you want the function to return a value, you can specify the return type and use the return statement to specify the value to be returned. For example:

int add(int x, int y)

{

return x + y;

}

This function has a return type of int and returns the sum of its two arguments.It's generally a good practice to explicitly specify the return type of a function, even if it's int, to make it clear to the reader what the function is expected to return.

Step-by-step explanation:

User Ket
by
3.0k points