Bifalgorithm post · Computer science one · Quadratic Roots

How can the return value communicate errors when roots are passed by reference?

How can the return value communicate errors when roots are passed by reference? (Computer science one · Quadratic Roots) — "We also note that the return value…

Ideas in this flowchart

  • The return value is available for communicating errors
  • The roots are returned through two pass-by-reference variables
  • Therefore, the function's return value is not needed for returning the roots
  • The return value can instead communicate errors to the calling function
  • Several inputs may be invalid
  • The roots could be complex values
  • The coefficient a could be zero
  • The pointers could be invalid because they point to NULL
  • The next chapter examines how different errors can be communicated and handled by the calling function
Feed/

How can the return value communicate errors when roots are passed by reference?

No cover

Channel

Computer science one

1 page

"We also note that the return value in this case is unused since we are “returning” the root values in the two pass-by-reference variables. This frees up the return value to be used to communicate errors to the calling function. Recall that there could be several “bad” inputs to this function. The roots could be complex values, the coefficient a could be zero, etc. And now that we are dealing with pointers, the pointers could be invalid (point to NULL). In the next chapter, we examine how we can use the return value to communicate different errors to the calling function, letting it handle those errors."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.