What will happen if a function does not return a value but has a return type other than void?
- It will cause a runtime error.
- It will return a random value.
- The program will not compile.
- The function will return zero.
When a function in C++ is declared with a return type other than void, it's a promise that the function will return a value of that type. If the function does not return any value, it will lead to a compilation error because the contract of returning a value (as per its declaration) is violated.
Loading...
Related Quiz
- If you want to force floating-point division in C++ when dividing two integers, one of the numbers should be _______.
- Which of the following is a characteristic of an enum in C++?
- Which of the following data types is not a primitive data type in C++?
- The members of a struct are _______ by default.
- You're developing an embedded system with constrained memory. What should be the main consideration when choosing between using float and double data types?