Questions tagged [function-parameter]

The function parameters are the variable names, listed in the definition of the function.

In many programming languages, parameters are the essence of the functions. The function parameters define the variable names, listed in the definition of the function. They are often confused with (and referred to as) function arguments, which actually are the real values that are passed to and received by the function when it is being called.

314 questions
396
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
  • 2,038
  • 3
  • 23
  • 27
348
votes
34 answers

How to get function parameter names/values dynamically?

Is there a way to get the function parameter names of a function dynamically? Let’s say my function looks like this: function doSomething(param1, param2, .... paramN){ // fill an array with the parameter name and value // some other code…
vikasde
  • 5,681
  • 10
  • 45
  • 62
137
votes
5 answers

Proper way to receive a lambda as parameter by reference

What is the right way to define a function that receives a int->int lambda parameter by reference? void f(std::function< int(int) >& lambda); or void f(auto& lambda); I'm not sure the last form is even legal syntax. Are there other ways to define…
lurscher
  • 25,930
  • 29
  • 122
  • 185
127
votes
4 answers

Python - use list as function parameters

How can I use a Python list (e.g. params = ['a',3.4,None]) as parameters to a function, e.g.: def some_func(a_char,a_float,a_something): # do stuff
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
81
votes
4 answers

Skipping optional function parameters in JavaScript

Could you please point me to the nice way of skipping optional parameters in JavaScript. For example, I want to throw away all opt_ parameters here: goog.net.XhrIo.send(url, opt_callback, opt_method, opt_content, {'Cache-Control': 'no-cache'},…
Dan
  • 55,715
  • 40
  • 116
  • 154
80
votes
5 answers

How to create a polyvariadic haskell function?

I need a function which takes an arbitrary number of arguments (All of the same type), does something with them and afterwards gives a result back. A list of arguments is impracticable in my specific case. As I looked through the haskell libs, I saw…
fuz
  • 88,405
  • 25
  • 200
  • 352
74
votes
2 answers

What do * (single star) and / (slash) do as independent parameters?

In the following function definition, what do the * and / account for? def func(self, param1, param2, /, param3, *, param4, param5): print(param1, param2, param3, param4, param5) NOTE: Not to mistake with the single|double asterisks in *args |…
ibarrond
  • 6,617
  • 4
  • 26
  • 45
74
votes
3 answers

When a function has a specific-size array parameter, why is it replaced with a pointer?

Given the following program, #include using namespace std; void foo( char a[100] ) { cout << "foo() " << sizeof( a ) << endl; } int main() { char bar[100] = { 0 }; cout << "main() " << sizeof( bar ) << endl; foo( bar…
CsTamas
  • 4,103
  • 5
  • 31
  • 34
72
votes
15 answers

How to deal with name/value pairs of function arguments in MATLAB

I have a function that takes optional arguments as name/value pairs. function example(varargin) % Lots of set up stuff vargs = varargin; nargs = length(vargs); names = vargs(1:2:nargs); values = vargs(2:2:nargs); validnames = {'foo', 'bar', 'baz'};…
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
43
votes
2 answers

What is the purpose of the "volatile" keyword appearing inside an array subscript?

While I was browsing cppreference, I saw a strange type array in function parameters like this: void f(double x[volatile], const double y[volatile]); So, What is the purpose of the volatile keyword appearing inside an array subscript? What does it…
msc
  • 33,420
  • 29
  • 119
  • 214
38
votes
4 answers

Maximum number of parameters in function declaration

I know that minimum number of parameters in function definition is zero, but what is the maximum number of parameters in function definition? I am asking the question just for the sake of knowledge and out of curiosity, not that I am going to write…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
36
votes
2 answers

Why use an asterisk "[*]" instead of an integer for a VLA array parameter of a function?

When using variable-Length Array as parameter in function int sum(int n, int a[n]); it is easy to understand first parameter(n) specifies the length of the second parameter(a). But encountered with another prototype used for VLAs as parameter …
haccks
  • 104,019
  • 25
  • 176
  • 264
29
votes
10 answers

Assign function arguments to `self`

I've noticed that a common pattern I use is to assign SomeClass.__init__() arguments to self attributes of the same name. Example: class SomeClass(): def __init__(self, a, b, c): self.a = a self.b = b self.c = c In fact…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
29
votes
3 answers

How can I pass-through parameters in a powershell function?

I have a function that looks something like this: function global:Test-Multi { Param([string]$Suite) & perl -S "$Suite\runall.pl" -procs:$env:NUMBER_OF_PROCESSORS } I would like to allow the user to specify more parameters to Test-Multi and…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
27
votes
5 answers

PHP: variable-length argument list by reference?

Is it possible to create a PHP function that takes a variable number of parameters all of them by reference? It doesn't help me a function that receives by reference an array of values nor a function that takes its arguments wrapped in an object…
1
2 3
20 21