0

Okay so in the PrintName function, it contains a printf function. However, I read that printf returns a value which is the number of characters. Shouldn't PrintName hence return an int as well? Thanks!

1

Good question. There is no requirement to capture a return value. Just because a function returns a value doesn't mean that the calling code needs to do anything with it. For many functions, like printf, it is common to disregard the return value. However, when there are bugs in a program, those return values can become useful in diagnosing and debugging.

To extend the concept, what if a function calls multiple other functions that all return values, maybe even different value types. What is it supposed to return then? Again, there's no requirement to return anything. It's up to the programmer to decide what, if anything, to return.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • Hmmm I am somewhat seeing the light... but just for additional clarification, under what circumstances is having a return value necessary? I know this sounds a bit stupid but if it's up to the programmer, what's the purpose of return values then? Thank you! – moosemoose96 Apr 24 '16 at 0:45
  • Most existing library functions return something, either a calculated result for which they were designed (ex: toupper()),maybe a diagnostic result describing success, a degree of success, or an indicator of the type of failure that may have occurred, even though they may carry out their prescribed function (ex: fopen() ). For something you're creating, it's up to you to determine whether a return value is necessary, optional, or desired. Does your function calculate a value and return it? Does it do something like print that needs no return? Don't care about the result? It's up to you. – Cliff B Apr 24 '16 at 0:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .