PCEP-30-02 · Question #210
Which of the following function definition does not return any value?
The correct answer is C. A function that prints integers from 1 to 100. Option C is correct because a function that prints integers performs output as a side effect - it sends text to the console but does not produce a value that can be used or stored by the caller. In most languages, such a function implicitly returns void (or None in Python)…
Question
Options
- AA function that converts an uppercase letter to lowercase.
- BA function that returns a random integer from 1 to 100.
- CA function that prints integers from 1 to 100.
How the community answered
(21 responses)- A10% (2)
- B19% (4)
- C71% (15)
Explanation
Option C is correct because a function that prints integers performs output as a side effect - it sends text to the console but does not produce a value that can be used or stored by the caller. In most languages, such a function implicitly returns void (or None in Python), meaning there is nothing to assign or pass on.
Option A is wrong because converting uppercase to lowercase must return the resulting character - otherwise the caller has no way to use the converted letter. Option B is wrong because generating a random integer only makes sense if that integer is returned to whoever called the function.
Memory tip: Ask yourself, "Could I store the result in a variable and use it later?" If yes, it returns a value. Printing just displays - it hands nothing back.
Community Discussion
No community discussion yet for this question.