Why we use parameters in function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why we use parameters in function?

Like a function that is use 2 parameters.

15th Nov 2018, 12:27 PM
Safiullah anis
Safiullah anis - avatar
4 Answers
+ 1
Which language?
15th Nov 2018, 12:31 PM
HonFu
HonFu - avatar
+ 22
well , there is so much of use of it parameters provide some values to a function on which some operation has to be applied . For example : U need to add 5 to a number entered x , U want to do it through a method then U can do it like x=addFiveTo(x); //here U have passed x as parameter in function x static int addFiveTo(int b) { return b+5; } //U can do many complex operations also on x , using it now U have to do same for some number b b=addFiveTo(b); //U can more of such functions taking parameters for different purposes , when U will start making programs on challenges & other problems , u will get to know how much useful they are
15th Nov 2018, 1:49 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
Sometimes you want to use a function multiple times, but want a different result on each call. Thats where you need to pass a parameter(s). For example you need to calculate factorial multiple times in your code with different input. Instead of create factorial code each time you need one with different number, you can create a function for it, and pass the input as parameter.
15th Nov 2018, 1:13 PM
Taste
Taste - avatar
+ 2
Thanks a lot for suggestions
16th Nov 2018, 6:31 AM
Safiullah anis
Safiullah anis - avatar