+ 2

Variables vs Paramaters

I cant seem to distinguish a variable vs a paramater can anybody explain the difference between them. People say paramaters are like temporary variables what exactly does that mean?

1st Jul 2023, 12:28 AM
Junior
Junior - avatar
8 odpowiedzi
+ 6
// An example says more than a thousand words // a and b are parameters public int addAmp(int a, int b) { int k = 2; // k is a variable return k*(a + b); } // 2 and 3 are arguments (parameter values) // sum is a variable var sum = addAmp(2, 3);
1st Jul 2023, 12:26 PM
JaScript
JaScript - avatar
+ 3
Made me very happy
2nd Jul 2023, 5:18 PM
JaScript
JaScript - avatar
+ 2
VARIABLES : x = 10 # Here, 'x' is a variable that holds the value 10. name = "John" # 'name' is a variable that holds the string "John". PARAMETERS : def add_numbers(a, b): # 'a' and 'b' are parameters. return a + b result = add_numbers(5, 7) # In this call, 5 and 7 are the arguments passed to the 'add_numbers' function. # Inside the function, 'a' will be assigned the value 5, and 'b' will be assigned the value 7. # The function will return 5 + 7 = 12, and that value will be stored in the 'result' variable.
1st Jul 2023, 6:32 AM
Kakashi はたけ
Kakashi はたけ - avatar
+ 1
Parameters are passed inside a function while variables are declared like INt a=1,string s etc.
1st Jul 2023, 4:19 AM
Jayesh Mishra
Jayesh Mishra - avatar
+ 1
Thanks
2nd Jul 2023, 3:28 PM
Junior
Junior - avatar
+ 1
I understand now
2nd Jul 2023, 3:29 PM
Junior
Junior - avatar
0
Let’s take a real life example to clarify your question. I suppose you used MS Excel at some point. Says in cell “A1”, you enter =SUM(1, 4). In here the number 1 and 4 are parameters for the SUM function. Now we add some more. Says in cell “A2” you entered 10, and in cell “A3” you entered 20. Back to A1, we change the formula to =SUM(A2, A3). Now A2 and A3 are parameters for function SUM, in the meantime they are also a variable, where A2 represent 10 and A3 represent 20. Back in coding we say: X = 10 Y = 20 print(X + Y) PS. It can be console.log, printf or something else, depends on which language you use. Here, X and Y are variables representing 10 and 20, meanwhile they also are parameters for function print.
1st Jul 2023, 7:02 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Haile
2nd Jul 2023, 5:10 PM
Haile Liul
Haile Liul - avatar