andyw27
asked on
Confused - Functions
I'm trying to get my head round using functions in C.
I understand that I have to declare a prototype but the thing which is confusing me the most is passing the values back and fourth from several functions ?
Can anybody explain the basic principles of this please (in laymans terms) ?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
andyw27:
Think of it that one function returns a value and another function takes this value, uses it and returns its own value.
Think of it that one function returns a value and another function takes this value, uses it and returns its own value.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks some useful advice, I will now go away and try work through the code given here.
Give your feedback on this.
If you have still some confusions/questions left, we can try to help you based on your feedback.
If every thing is really answered, then close the question.
-ssnkumar
If you have still some confusions/questions left, we can try to help you based on your feedback.
If every thing is really answered, then close the question.
-ssnkumar
Functions are the modules which may or may not return a value, if returns it is unique value.
When we invoke the function compiler searches for viable functions, then it decides which function to invoke amongst the vaiable functions. If there is no such functions generates an error. the arguments or parameters are communicated between function call statement and function called thru stack. If the parameter itself is a function call, compiler has to check return type of the function whether it will match the required parameter at that position.
void fcn(int,int,double)
can be inoked like fcn([integer constant or function that returns integer compatible data],[integer constant or function that returns integer compatible data],[double constant / function returning double data] )
During the call implicit conversion will be done if needed.
When we invoke the function compiler searches for viable functions, then it decides which function to invoke amongst the vaiable functions. If there is no such functions generates an error. the arguments or parameters are communicated between function call statement and function called thru stack. If the parameter itself is a function call, compiler has to check return type of the function whether it will match the required parameter at that position.
void fcn(int,int,double)
can be inoked like fcn([integer constant or function that returns integer compatible data],[integer constant or function that returns integer compatible data],[double constant / function returning double data] )
During the call implicit conversion will be done if needed.
A split ??
I think all the answers deserve points :)
stefan73,
me,
ssnkumar,
harshadp
Is that ok?
stefan73,
me,
ssnkumar,
harshadp
Is that ok?
Thanks for counting me in Harish:-))
int add3(int input){
return input + 3;
}
int myvar = 5;
myvar = add3(myvar+add3(myvar));
...and myvar will be ((5+ ((5)+3))+3) = 16.