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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *