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.

279 questions
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
318
votes
33 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,301
  • 9
  • 42
  • 61
111
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
  • 84,911
  • 94
  • 244
  • 345
97
votes
5 answers

c++0x: 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
  • 23,085
  • 26
  • 113
  • 178
73
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
  • 76,641
  • 24
  • 165
  • 316
71
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
  • 3,803
  • 5
  • 28
  • 34
69
votes
3 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
  • 48,995
  • 35
  • 110
  • 141
69
votes
14 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
  • 107,354
  • 40
  • 225
  • 343
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
  • 30,333
  • 19
  • 96
  • 184
33
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
  • 97,141
  • 23
  • 153
  • 244
31
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
  • 327,095
  • 105
  • 629
  • 812
26
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
  • 84,911
  • 94
  • 244
  • 345
25
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…
23
votes
4 answers

Passing arguments to functions with const parameters: is it faster?

Consider, for example: int sum(int a, int b) { return a + b; } vs. int sum(const int a, const int b) { return a + b; } Is the second approach in general faster? Function parameters in C are copied and sent to the function, so that changes…
becko
  • 13,246
  • 24
  • 74
  • 144
21
votes
4 answers

Why is the function argument not overwritten on creating variable of same name inside the function?

var a = 'why is this not undefined?'; function checkScope(a) { var a; console.log(a); } checkScope(a); Javascript is functional scope language, right? When I declare a new variable just inside the function that uses the same name as the…
user3932668
  • 255
  • 2
  • 8
1
2 3
18 19