Parameters and Variables

Hello.
In simple English
Can we just say that parameters are the mathematical rule or equation ?
And variable is the changing values that produce a different parameter?

so can we say that c is a parameter in c = a + b ? and a and b are variables ?

This is what I checked :
http://www.answers.com/topic/parameter?cat=biz-fin
http://www.answers.com/topic/variable
What confuses me, why are a & b parameters , what about C here :
http://www.cplusplus.com/doc/tutorial/functions/
You can compare C++ function syntax to the general form y = f(x), where y is the result and f(x) is the function. Here, you can think of y as the return value from the function, f is the name of the function, and x is the parameter/variable of the function. In addition, when you have f(x,y) = x + y, x and y are the parameters while "x+y" is like the function body where the work is done to return a result.
so in:

func_1 (int x,y) // parameters because they change according to input
{
f = y + x ; // variable?
return f;
}
int main()
{
z = func_1(1,2); // Z variable, func_1 and its values parametrs
}

------
and in:
cin>>y>>x;
f = y + x ; // variables?
Last edited on
func_1 (int x,y)

Yes, x and y are the parameters (not func_1), just as they are in a mathematical form f(x,y).
However, you cannot declare functions like that:
 
int func_1(int x, int y)


In addition, in your function bodies, f and z have never been declared before.
1
2
3
int f = y + x;
//...
int z = func_1(1,2);



cin>>y>>x;
f = y + x ; // variables?

In both cases above, x and y are the parameters. Believe it or not, cin is also a parameter.
f = y + x ~ f(x,y) = y + x
cin >> y >> x ~ operator>>(operator>>(cin, y) , x)
Last edited on
then what if I type
1
2
3
4
5
6
7
int main()
{
int a=5;  //variable
int b;      //variable
 cin>>b;  //now b is a parameter
int c = a + b ;   // a is still a variable, b parameter, c parameter
cout << c;


so in conclusion
can I say
parameter is the changing value in a test
variable is the constant value that does not change in a test
Last edited on
a, b, and c are variables but are used as parameters for a function. Like if you had a variable A0 to represent the area of a cylinder and h0 a variable to represent the height. Then, you'd have a function V(A,h) to calculate the volume of the cylinder, where A and h are parameters.
Then say we have V0 = V(A0,h0). Here you see the variables A0 and h0 used as parameters (or crudely speaking, the limitations of the function). Note also, that V0 is a variable but not a parameter because it is not being used as data to calculate something. In addition, you can use functions as parameters, like say we expanded V(A,h) to V(A(r),h) where now A(r) calculates the area of a cylinder's base given the radius.

In:
 
int c = a + b;

You can expand it to the following to make things extra clear (though less legible):
1
2
int c;
operator= (c, operator+ (a,b));

Here you can see a and b used as parameters. Then, the result of the function operator+ is passed in as a parameter to another function, operator=. At this point, c is now passed in as a parameter. So, a and b are parameters while c is a parameter depending on which function you are focusing on.
Thank you for your explanation , I finally cout<<"GOT IT, LOL
Last edited on
one more thing
when returning functions by variables, we can only return 1;
but when by reference the whole variable is changed, so we can get more than 1 value?
Think of it this way, the words "parameter" and "variable" are just used to describe certain things in programming so we as humans can understand what we're talking about.

1
2
3
4
5
6
7
8
int myVariable; //This is a variable named myVariable. 

//Parameters are ONLY used when talking about functions.
//This is a function. It has two parameters.
int myFunction(int myFirstParameter, int mySecondParameter)
{
    int myLocalVariable; //This is a variable named myLocalVariable.
}


parameter is the changing value in a test
variable is the constant value that does not change in a test


No. The words "parameter" and "variable" have nothing to do with that. They are only used to describe things.

- A variable is something that has a name and a type.
- Parameter is only used when talking about functions.
but when by reference the whole variable is changed, so we can get more than 1 value?

If you are thinking about sending your output through parameters, then yes.

1
2
3
4
void funky(int a, int b, int& c, int& d){
   c = a+b;
   d = c - a/b;
}

You have "returned" two values.
I think I got confused because I got statistics class, because I am not pure IT, but Business IT.

any way I finally got it in math logic and in programming, woah how I feel much better now

Thanks guys, I was going to lose a fuse in my head if it wasn't for you.
Topic archived. No new replies allowed.