Questions tagged [parameter-passing]

parameter-passing is the process of assigning values to the parameters of a function

Association of actual and formal parameters upon function call. See Parameter Passing and its methods. The most widely used parameter passing methods are:

  • call-by-value
  • call-by-reference
  • call-by-value-result
  • call-by-name
  • call-by-need
  • macro expansion.
8028 questions
177
votes
6 answers

Java variable number of arguments for a method

Is it possible to declare a method that will allow a variable number of parameters ? What is the symbolism used in the definition that indicate that the method should allow a variable number of parameters? Answer: varargs
user69514
  • 26,935
  • 59
  • 154
  • 188
170
votes
4 answers

Passing an Array as Arguments, not an Array, in PHP

I seem to remember that in PHP there is a way to pass an array as a list of arguments for a function, dereferencing the array into the standard func($arg1, $arg2) manner. But now I'm lost on how to do it. I recall the manner of passing by…
Robert K
  • 30,064
  • 12
  • 61
  • 79
170
votes
22 answers

Can we pass parameters to a view in SQL?

Can we pass a parameter to a view in Microsoft SQL Server? I tried to create view in the following way, but it doesn't work: create or replace view v_emp(eno number) as select * from emp where emp_id=&eno;
arunachalam
  • 1,889
  • 3
  • 13
  • 6
149
votes
3 answers

How are strings passed in .NET?

When I pass a string to a function, is a pointer to the string's contents passed, or is the entire string passed to the function on the stack like a struct would be?
Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
135
votes
3 answers

Difference between passing array and array pointer into function in C

What is the difference between the two functions in C? void f1(double a[]) { //... } void f2(double *a) { //... } If I were to call the functions on a substantially long array, would these two functions behave differently, would they take…
Kaushik Shankar
  • 5,491
  • 4
  • 30
  • 36
133
votes
16 answers

PHP Function with Optional Parameters

I've written a PHP function that can accept 10 parameters, but only 2 are required. Sometimes, I want to define the eighth parameter, but I don't want to type in empty strings for each of the parameters until I reach the eighth. One idea I had was…
user481826
  • 1,365
  • 2
  • 9
  • 4
131
votes
2 answers

Pass parameter to EventHandler

I have the following EventHandler to which I added a parameter MusicNote music: public void PlayMusicEvent(object sender, EventArgs e,MusicNote music) { music.player.Stop(); System.Timers.Timer myTimer = (System.Timers.Timer)sender; …
Matt
  • 3,820
  • 16
  • 50
  • 73
129
votes
11 answers

Passing an array as an argument to a function in C

I wrote a function containing array as argument, and call it by passing value of array as follows. void arraytest(int a[]) { // changed the array a a[0] = a[0] + a[1]; a[1] = a[0] - a[1]; a[0] = a[0] - a[1]; } void main() { int…
Mohan Mahajan
  • 1,501
  • 3
  • 12
  • 19
128
votes
21 answers

How to return an array in bash without using globals?

I have a function that creates an array and I want to return the array to the caller: create_array() { local my_list=("a", "b", "c") echo "${my_list[@]}" } my_algorithm() { local result=$(create_array) } With this, I only get an expanded…
helpermethod
  • 59,493
  • 71
  • 188
  • 276
120
votes
17 answers

Best practice for passing many arguments to method?

Occasionally , we have to write methods that receive many many arguments , for example : public void doSomething(Object objA , Object objectB ,Date date1 ,Date date2 ,String str1 ,String str2 ) { } When I encounter this kind of problem , I often…
Sawyer
  • 15,581
  • 27
  • 88
  • 124
119
votes
11 answers

In Javascript/jQuery what does (e) mean?

I am new to JavaScript/jQuery and I've been learning how to make functions. A lot of functions have cropped up with (e) in brackets. Let me show you what I mean: $(this).click(function(e) { // does something }); It always appears that the…
shrewdbeans
  • 11,971
  • 23
  • 69
  • 115
116
votes
4 answers

Django return redirect() with parameters

In my view function I want to call another view and pass data to it : return redirect('some-view-name', backend, form.cleaned_data) , where backend is of registration.backends object, and form.cleaned_data is a dict of form data (but both must be…
muntu
  • 2,355
  • 4
  • 19
  • 18
112
votes
7 answers

Bash: pass a function as parameter

I need to pass a function as a parameter in Bash. For example, the following code: function x() { echo "Hello world" } function around() { echo "before" eval $1 echo "after" } around x Should output: before Hello world after I know eval…
cd1
  • 15,908
  • 12
  • 46
  • 47
108
votes
5 answers

When to use an object instance variable versus passing an argument to the method

How do you decide between passing arguments to a method versus simply declaring them as object instance variables that are visible to all of the object's methods? I prefer keeping instance variables in a list at the end of the Class, but this list…
Ziggy
  • 21,845
  • 28
  • 75
  • 104
104
votes
4 answers

How can I pass selected row to commandLink inside dataTable or ui:repeat?

I'm using Primefaces in a JSF 2 application. I have a , and instead of selecting rows, I want the user to be able to directly execute various actions on individual rows. For that, I have several s in the last column. My…
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720