bool is_something_ok(int param,SomeStruct* p) { bool is_ok = false; // check if is_ok if(is_ok) // set p to some valid value else // set p to NULL return is_ok; }
this function return true and set p to a valid value if "something is ok" otherwise return false and set p to NULL
Is that a good or bad design? personally, i feel uncomfortable when i use it. If there is no document and comment, i really don know how to use it.
BTW:Is there some authoritative book/article about API design?
Goal: Parameters and return values allow students to write programs that are more organized and cleaner. Naming functions helps students write programs that read more like descriptions of what they do, and they also help students reuse code.
The parameter is a string in which you will count the words. The argument is any string you pass to your function when you call it. The return value is the number of words.
A return value is a result of the function's execution. It can be returned to the block of code that called the function, and then used as needed. Parameters are the necessary input for a function to be executed and produce a result. Parameters are variables defined by name.
Introduction. A function can take parameters to use in its code, and it can return zero or more values (when more values are returned, one of the values often speaks of a tuple of values).
Since you have tagged the question as C++ and not C, I would suggest you to:
But that are just some general hints. The best way to go always depends on the specific problem...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With