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
325
votes
9 answers

Passing Objects By Reference or Value in C#

In C#, I have always thought that non-primitive variables were passed by reference and primitive values passed by value. So when passing to a method any non-primitive object, anything done to the object in the method would effect the object being…
Michael
  • 8,229
  • 20
  • 61
  • 113
311
votes
8 answers

jQuery's .click - pass parameters to user function

I am trying to call a function with parameters using jQuery's .click, but I can't get it to work. This is how I want it to work: $('.leadtoscore').click(add_event('shot')); which calls function add_event(event) { blah blah blah } It works if I…
Paul Hoffer
  • 12,606
  • 6
  • 28
  • 37
281
votes
3 answers

Pass a list to a function to act as multiple arguments

In a function that expects a list of items, how can I pass a Python list item without getting an error? my_list = ['red', 'blue', 'orange'] function_that_needs_strings('red', 'blue', 'orange') # works! function_that_needs_strings(my_list) #…
AP257
  • 89,519
  • 86
  • 202
  • 261
280
votes
7 answers

Are there benefits of passing by pointer over passing by reference in C++?

What are the benefits of passing by pointer over passing by reference in C++? Lately, I have seen a number of examples that chose passing function arguments by pointers instead of passing by reference. Are there benefits to doing…
Matt Pascoe
  • 8,651
  • 17
  • 42
  • 48
276
votes
0 answers

Pass ALL Arguments from Bash Script to Another Command

What is the simplest way to grab all the given arguments for a bash script and pass them all into another command within the script? For example: Command Line: ./runProgram.sh [ARGS HERE] Script: #! /bin/bash cd bin/ java com.myserver.Program [ARGS…
Urda
  • 5,460
  • 5
  • 34
  • 47
256
votes
9 answers

How do I pass a method as a parameter in Python

Is it possible to pass a method as a parameter to a method? self.method2(self.method1) def method1(self): return 'hello world' def method2(self, methodToRun): result = methodToRun.call() return result
Dan
  • 3,636
  • 2
  • 24
  • 24
228
votes
10 answers

How to return a value from a Form in C#?

I have a main form (let's call it frmHireQuote) that is a child of a main MDI form (frmMainMDI), that shows another form (frmImportContact) via ShowDialog() when a button is clicked. When the user clicks the 'OK' on frmImportContact, I want to pass…
Jez Clark
  • 2,919
  • 4
  • 26
  • 31
227
votes
6 answers

jQuery - add additional parameters on submit (NOT ajax)

Using jQuery's 'submit' - is there a way to pass additional parameters to a form? I am NOT looking to do this with Ajax - this is normal, refresh-typical form submission. $('#submit').click(function () { $('#event').submit(function () { …
Ciel
  • 17,312
  • 21
  • 104
  • 199
225
votes
10 answers

Passing Parameters JavaFX FXML

How can I pass parameters to a secondary window in javafx? Is there a way to communicate with the corresponding controller? For example: The user chooses a customer from a TableView and a new window is opened, showing the customer's info. Stage…
Alvaro
  • 11,797
  • 9
  • 40
  • 57
199
votes
11 answers

How can we force naming of parameters when calling a function?

In Python you may have a function definition: def info(obj, spacing=10, collapse=1) which could be called in any of the following ways: info(odbchelper) info(odbchelper, 12) info(odbchelper, collapse=0) …
Mark Mayo
  • 12,230
  • 12
  • 54
  • 85
199
votes
19 answers

Passing parameters to JavaScript files

Often I will have a JavaScript file that I want to use which requires certain variables be defined in my web page. So the code is something like this: