+ 5
Can the parameter passed be a variable?
I couldn't help thinking how this would be really useful to pass the value from another part of the program into the function.
2 Answers
+ 4
No , you cannot pass a variable . More over you don't pass parameters actually it's argument which is passed to the parameters . For example-
//function declared as pass_code
int pass_code( int a, int b) // a and b are parameters
{
return a*b;
}
pass_code(3,8); /* 3 and 8 are arguments passed by calling the pass_code function */
0
You cannot pass a variable to a function, instead you can pass the value of a variable.
If you want to use the same variable in different functions, then simply declare that variable globally. One important thing here that you should keep in mind is the value of global variables can be manipulated by all the functions where it is used.