0 votes
in C Plus Plus by
What are the consequences of not using a return statement in a function that has a non-void return type?

1 Answer

0 votes
by

A function with a non-void return type is expected to return a value. If no return statement is used, the behavior of the program becomes undefined. This means that it may work as intended in some cases but fail unpredictably in others. The compiler might not catch this error and will likely generate a warning instead. It’s crucial to ensure all code paths in such functions reach a return statement to avoid unpredictable results or potential crashes.

...