Question:
What's a parameter do?
sirhouse
2012-04-18 12:29:19 UTC
Ok so I've never really undestood what a parameter is/does. Why do we need those extra variables in the parathesis? I really don't understand anything about them at all except for the fact that they're a variable. Thanks!
Three answers:
Priyanka
2012-04-18 12:34:55 UTC
In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are called arguments. An ordered list of parameters is usually included in the definition of a subroutine, so that, each time the subroutine is called, its arguments for that call can be assigned to the corresponding parameters.
2012-04-18 19:37:09 UTC
They are variables that exist within the current scope. You use them to give your method or constructor material to work with.



For example I have a method that draws a line, let's call it drawLine() (this is in Java, in C# it'd be DrawLine()). I could give it 4 parameters: the coordinate of the starting point, the coordinate of the starting point, the coordinate of the ending point and the coordinate of the ending point.



It would look like this: drawLine(xStart, yStart, xEnd, yEnd);



With these parameters your method knows where to put the line exactly. You can let the user choose the parameters or give the values yourself. The point is that the method will become more useful if you give it parameters (of course some methods like toString() don't need parameters since, in the toString case, they take information out of the class itself).



I can be more specific but it's a pretty broad question...
2012-04-18 19:33:20 UTC
there not variables all the time basically they change the properties of a function for example in thefollowingg statement imakee a window 600 by 400pixelss in 32bit.



SDL_SetVideoMode(600, 400, 32, OPEN_GL);



Example using C++ with SDL


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...