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.
22681 questions
170
votes
7 answers

Passing just a type as a parameter in C#

Hypothetically it'd be handy for me to do this: foo.GetColumnValues(dm.mainColumn, int) foo.GetColumnValues(dm.mainColumn, string) where the GetColumns method will call a different method inside depending on the type passed. Yes, I could do it as a…
Mark Mayo
  • 12,230
  • 12
  • 54
  • 85
164
votes
15 answers

How many constructor arguments is too many?

Let's say you have a class called Customer, which contains the following fields: UserName Email First Name Last Name Let's also say that according to your business logic, all Customer objects must have these four properties defined. Now, we can do…
Kevin Pang
  • 41,172
  • 38
  • 121
  • 173
148
votes
5 answers

Declare a block method parameter without using a typedef

Is it possible to specify a method block parameter in Objective-C without using a typedef? It must be, like function pointers, but I can't hit on the winning syntax without using an intermediate typedef: typedef BOOL (^PredicateBlock_t)(int); -…
Bogatyr
  • 19,255
  • 7
  • 59
  • 72
148
votes
2 answers

AngularJS ui router passing data between states without URL

I am facing this problem of passing data between two states without exposing the data in the url, it's like user cannot really directly land on this state. For example. I have two states "A" and "B". I am doing some server call in state "A" and…
vijay tyagi
  • 2,226
  • 3
  • 20
  • 31
147
votes
2 answers

How to handle more than 10 parameters in shell

I am using bash shell on linux and want to use more than 10 parameters in shell script
Ashitosh
  • 1,652
  • 3
  • 12
  • 11
144
votes
2 answers

How do I pass parameters into a PHP script through a webpage?

I am calling a PHP script whenever a webpage loads. However, there is a parameter that the PHP script needs to run (which I normally pass through the command line when I am testing the script). How can I pass this argument every time the script is…
Nick
  • 1,793
  • 2
  • 15
  • 13
141
votes
14 answers

How to pass parameters to a Script tag?

I read the tutorial DIY widgets - How to embed your site on another site for XSS Widgets by Dr. Nic. I'm looking for a way to pass parameters to the script tag. For example, to make the following work:
Tomer Lichtash
  • 9,002
  • 16
  • 55
  • 71
141
votes
9 answers

Passing a method as a parameter in Ruby

I am trying to mess around a little bit with Ruby. Therefor I try to implement the algorithms (given in Python) from the book "Programming Collective Intelligence" Ruby. In chapter 8 the author passes a method a as parameter. This seems to work in…
Christian Stade-Schuldt
  • 4,671
  • 7
  • 35
  • 30
138
votes
8 answers

What is the difference between a const reference and normal parameter?

void DoWork(int n); void DoWork(const int &n); What's the difference?
Pirate for Profit
  • 1,591
  • 2
  • 14
  • 16
137
votes
5 answers

Script parameters in Bash

I'm trying to make a shell script which should be used like this: ocrscript.sh -from /home/kristoffer/test.png -to /home/kristoffer/test.txt The script will then ocr convert the image file to a text file. Here is what I have come up with so…
Kristoffer
  • 1,984
  • 3
  • 14
  • 29
136
votes
7 answers

How to set a Django model field's default value to a function call / callable (e.g., a date relative to the time of model object creation)

EDITED: How can I set a Django field's default to a function that gets evaluated each time a new model object gets created? I want to do something like the following, except that in this code, the code gets evaluated once and sets the default to the…
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
133
votes
7 answers

PostgreSQL: How to pass parameters from command line?

I have a somewhat detailed query in a script that uses ? placeholders. I wanted to test this same query directly from the psql command line (outside the script). I want to avoid going in and replacing all the ? with actual values, instead I'd like…
vol7ron
  • 40,809
  • 21
  • 119
  • 172
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
121
votes
5 answers

Passing multiple values to a single PowerShell script parameter

I have a script to which I pass server name(s) in $args. This way I can do stuff to this (these) server(s) using foreach: .\script.ps1 host1 host2 host3 foreach ($i in $args) { Do-Stuff $i } I'd like to add a named optional parameter called…
jcarpio
  • 3,350
  • 5
  • 23
  • 22
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