Is it possible to have several return statements in a function? Does a return statement have to return a value? Explain both answers.

What will be an ideal response?


Yes it is possible to have several return statements in a function. You could have returns nested inside switch case statements or if/else if statements. The return does not have to return a value. If the function return type is void, you’d just use “return ;” to exit the function. If the function has a void return type, and program control flows to the “bottom” of the function, no return is needed.

Computer Science & Information Technology

You might also like to view...

MC The last line number in a traceback indicates the__________ .

a) throw point. b) catch point. c) handle point. d) None of the above.

Computer Science & Information Technology

Answer the following statement(s) true (T) or false (F)

1. The condition used in an if statement can be any valid C++ expression. 2. In C++, strings of characters cannot be compared. 3. A common problem with the if-else statement is using the assignment operator, =, in place of the relational operator ==. 4. Before the current ANSI/ISO C++ standard, C++ didn’t have a built-in Boolean data type with its two Boolean values, true and false. 5. In C++, the postfix and prefix -- operators can be applied to Boolean variables.

Computer Science & Information Technology

One of the most important aspects of DHTML is the Document Object Model (DOM).

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Colors that produce black when combined are called ____________________ and are used in commercial printing.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology