Can the parameter passed be a variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

16th Jul 2016, 8:34 AM
Marco Cesar Saenz
Marco Cesar Saenz - avatar
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 */
18th Jun 2017, 5:53 PM
Ritesh Behera
Ritesh Behera - avatar
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.
19th Jul 2016, 3:40 PM
Sourabh Deoghare
Sourabh Deoghare - avatar