Hi,
I understand that any function declared after a global variable can access that variable, and that a variable declared inside a function is local and can only be used by that function.
My first question is can that local variable declared in a function be passed as an argument to another function? And if it can, can it only be passed to a function whose definition comes after it or can it be passed to previous function definitons as well? Example: (see comments)
Code:double Tax(double returned_gross_pay) { double l; /*can this be passed to the next function?*/ l = returned_gross_pay * 0.15; return l; } double Net_Pay(double returned_net_pay, double returned_tax) { double m; /*can this be passed to the previous function?*/ m = returned_net_pay - returned_tax; return m; }
My other question is similar. With the functions themselves, I know that a function can contain another function that was defined after it. Example:
But can this also be done in reverse? Could I put Tax() inside Net_Pay() ?Code:double Tax(double returned_gross_pay) { double l, a; l = returned_gross_pay * 0.15; a = double Net_Pay(); /*the following function*/ return l; } double Net_Pay(double returned_net_pay, double returned_tax) { double m; m = returned_net_pay - returned_tax; return m; }



LinkBack URL
About LinkBacks


