Questions tagged [parameters]

Parameters are a type of variable used in a subroutine to refer to the data provided as input to the subroutine.

A parameter is an intrinsic property of a procedure, included in its definition. For example, in many languages, a minimal procedure to add two supplied integers together and calculate the sum total would need two parameters, one for each integer. In general, a procedure may be defined with any number of parameters, or no parameters at all. If a procedure has parameters, the part of its definition that specifies the parameters is called its parameter list.

There are two ways of passing parameters to a procedure (both of them may not be available in every programming language):

  • by value: the value of a variable (or constant, etc.) is passed to the procedure and the original variable cannot be affected by the code in the procedure.
  • by reference: the reference to a variable is passed to a procedure and the variable's value can be changed in the procedure.
19575 questions
2489
votes
28 answers

Set a default parameter value for a JavaScript function

I would like a JavaScript function to have optional arguments which I set a default on, which get used if the value isn't defined (and ignored if the value is passed). In Ruby you can do it like this: def read_file(file, delete_after = false) #…
Tilendor
  • 45,619
  • 15
  • 48
  • 58
1826
votes
25 answers

Does Java support default parameter values?

I came across some Java code that had the following structure: public MyParameterizedFunction(String param1, int param2) { this(param1, param2, false); } public MyParameterizedFunction(String param1, int param2, boolean param3) { //use all…
gnavi
  • 21,966
  • 7
  • 19
  • 11
1574
votes
8 answers

How are parameters sent in an HTTP POST request?

In an HTTP GET request, parameters are sent as a query string: http://example.com/page?parameter=value&also=another In an HTTP POST request, the parameters are not sent along with the URI. Where are the values? In the request header? In the request…
Camilo Martin
  • 34,128
  • 20
  • 104
  • 150
1181
votes
6 answers

What are the -Xms and -Xmx parameters when starting JVM?

Please explain the use of Xms and Xmx parameters in JVMs. What are the default values for them?
Pankaj
  • 12,220
  • 3
  • 15
  • 22
1128
votes
7 answers

Passing parameters to a Bash function

I am trying to search how to pass parameters in a Bash function, but what comes up is always how to pass parameter from the command line. I would like to pass parameters within my script. I tried: myBackupFunction("..", "...", "xx") function…
stivlo
  • 77,013
  • 31
  • 135
  • 193
1073
votes
40 answers

Parameterize an SQL IN clause

How do I parameterize a query containing an IN clause with a variable number of arguments, like this one? SELECT * FROM Tags WHERE Name IN ('ruby','rails','scruffy','rubyonrails') ORDER BY Count DESC In this query, the number of arguments could be…
Jeff Atwood
  • 60,897
  • 45
  • 146
  • 152
911
votes
28 answers

How can I pass a parameter to a setTimeout() callback?

I have some JavaScript code that looks like: function statechangedPostQuestion() { //alert("statechangedPostQuestion"); if (xmlhttp.readyState==4) { var topicId = xmlhttp.responseText; setTimeout("postinsql(topicId)",4000); …
Zeeshan Rang
  • 17,525
  • 27
  • 65
  • 96
814
votes
35 answers

What's the difference between an argument and a parameter?

When verbally talking about methods, I'm never sure whether to use the word argument or parameter or something else. Either way the other people know what I mean, but what's correct, and what's the history of the terms? I'm a C# programmer, but I…
rohancragg
  • 4,904
  • 5
  • 32
  • 44
738
votes
13 answers

Pass a JavaScript function as parameter

How do I pass a function as a parameter without the function executing in the "parent" function or using eval()? (Since I've read that it's insecure.) I have this: addContact(entityId, refreshContactList()); It works, but the problem is that…
imperium2335
  • 20,168
  • 36
  • 103
  • 181
691
votes
8 answers

How do you pass a function as a parameter in C?

I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?
andrewrk
  • 27,002
  • 25
  • 87
  • 105
689
votes
33 answers

How to get URL parameter using jQuery or plain JavaScript?

I have seen lots of jQuery examples where parameter size and name are unknown. My URL is only going to ever have 1 string: http://example.com?sent=yes I just want to detect: Does sent exist? Is it equal to "yes"?
LeBlaireau
  • 14,709
  • 30
  • 95
  • 169
625
votes
1 answer

"Parameter" vs "Argument"

I got parameter and argument kind of mixed up and did not really pay attention to when to use one and when to use the other. Can you please tell me?
dummy
569
votes
8 answers

What does int argc, char *argv[] mean?

In many C++ IDE's and compilers, when it generates the main function for you, it looks like this: int main(int argc, char *argv[]) When I code C++ without an IDE, just with a command line compiler, I type: int main() without any parameters. What…
Greg Treleaven
  • 6,976
  • 7
  • 27
  • 30
394
votes
11 answers

Why does a function with no parameters (compared to the actual function definition) compile?

I've just come across someone's C code that I'm confused as to why it is compiling. There are two points I don't understand. The function prototype has no parameters compared to the actual function definition. The parameter in the function…
AdmiralJonB
  • 1,896
  • 2
  • 18
  • 25
390
votes
4 answers

Passing a dictionary to a function as keyword parameters

I'd like to call a function in python using a dictionary. Here is some code: d = dict(param='test') def f(param): print(param) f(d) This prints {'param': 'test'} but I'd like it to just print test. I'd like it to work similarly for more…
Dave Hillier
  • 15,546
  • 8
  • 41
  • 85
1
2 3
99 100