0
Hi,when using user defined fxns,is it neccessary to print required values from main or from fxn definition or are there rules?
User defined function
11 Answers
+ 1
Sandesh Khanal
Answer to the question is contextual, it depends on some considerations. If you can show me the code, I may be able to help with that. But I can't say much without looking at a code : )
+ 1
For example if when you have to print two real roots in quad eqn there are two values you must return to calling fxn but that is not possible so the only way is to print from called fxn?
+ 1
I do know how to use those except for returning struct but there were some codes where the values where displayed from both main and called fxn so i guess both are fine to do?
0
Do you know the way to use pointer to pass in function argument? this is one possibility. Another way is to return a struct, or you can create a dynamic array and return the array (if the values are of the same type).
0
Personally, I prefer to have user defined functions to process the data and return the information to me. And if the user defined function is meant to only print the values, then I will set it as void function, and it shouldn't return anything.
But if you find that there's a need to print the values twice (in user defined function & in main), then I guess the choice is yours.
0
Alright then for returning struct can i create a structure struct root with members r1 and r2 and a fxn struct x(struct n) and just return the the whole struct and not just individual members?
0
You want to pass 'struct root' as function argument and return also 'struct root'? I didn't understand ...
0
How would you approach the question by using structure?
0
I'm sorry, but I didn't get "approaching the question" ...
0
I mean how would you solve it ?do you pass struct as arguments or just a fxn with return type and no arguments ?
0
Pass the "raw materials" as arguments to the function. Let the function "bake" it, and return to you the "cake". I think this is your idea?