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
27
votes
5 answers

C++ : Meaning of const char*const*

In one of the C++ programs, I saw a function prototype : int Classifier::command(int argc, const char*const* argv) What does const char*const* argv mean? Is it the same as const char* argv[]? Does const char** argv also mean the same?
vigs1990
  • 1,639
  • 4
  • 17
  • 19
25
votes
4 answers

Why should I declare a C array parameter's size in a function header?

Can anyone enlighten me as to why I should bother to specify the size of a C array argument in a function header? For example: void foo (int iz[6]) { iz[42] = 43; } With: int is[2] = {1,2,3}; we get a useful error. Perhaps it helps with…
user2023370
  • 10,488
  • 6
  • 50
  • 83
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…
a06e
  • 18,594
  • 33
  • 93
  • 169
21
votes
7 answers

C# enums as function parameters?

Can you pass a standard c# enum as a parameter? For example: enum e1 { //... } enum e2 { //... } public void test() { myFunc( e1 ); myFunc( e2 ); } public void myFunc( Enum e ) { // Iterate through all the values in e } By…
TK.
  • 46,577
  • 46
  • 119
  • 147
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
  • 3
  • 8
19
votes
1 answer

Default value for function parameters in VB6

How to specify default value for a parameter in VB6?
rkg
  • 5,559
  • 8
  • 37
  • 50
17
votes
9 answers

Using function arguments as local variables

Something like this (yes, this doesn't deal with some edge cases - that's not the point): int CountDigits(int num) { int count = 1; while (num >= 10) { count++; num /= 10; } return count; } What's your opinion…
Rubys
  • 3,167
  • 2
  • 25
  • 26
16
votes
3 answers

Difference call function with asterisk parameter and without

I know what the meaning of an asterisk is in a function definition in Python. I often, though, see asterisks for calls to functions with parameters like: def foo(*args, **kwargs): first_func(args, kwargs) second_func(*args, **kwargs) What…
Robert Moon
  • 1,025
  • 10
  • 17
15
votes
3 answers

Late destruction of function parameters

According to 5.2.2/4 "Function call" in n4640 (8.2.2/4 in n4659) function parameters are created and destroyed in the context of the caller. And implementations are allowed to delay the destruction of function parameters to the end of the enclosing…
AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
14
votes
3 answers

Passing inline double array as method argument

Consider method functionA (double[] arg) I want to pass a double array inline, like functionA({1.9,2.8}) and not create an array first and then pass it, like double var[] = {1.0,2.0}; functionA(var); Is this possible with C++? Sounds simple, but…
Eric
  • 1,594
  • 1
  • 15
  • 29
13
votes
3 answers

String in function parameter

int main() { char *x = "HelloWorld"; char y[] = "HelloWorld"; x[0] = 'Z'; //y[0] = 'M'; return 0; } In the above program, HelloWorld will be in read-only section(i.e string table). x will be pointing to…
Jeyaram
  • 9,158
  • 7
  • 41
  • 63
11
votes
3 answers

Is it valid to use a zero-sized non-static array function parameter?

Is it valid, according to ISO C (any version), to specify a zero-sized array parameter? The standard seems ambiguous. While it's clear that zero-sized arrays are invalid, array function parameters are special: C23::6.7.6.3/6: A declaration of a…
11
votes
2 answers

How to specify type that can be either integer or string

I have a function that its parameter should be integer or string. from typing import int,str def MyFunc(arg:int) -> None: print(arg) but I want to know how to write it to tell the user arg can be both int and str?
Ramin-RX7
  • 128
  • 1
  • 1
  • 13
11
votes
3 answers

How to avoid implicit conversions from integer 0 to pointer, as the element of a vector

There is a situation where I want to collect all the nodes names of a path to one key in JSON. Consider the condition: JSON array index "0", "1" are also allowed, but it is easy to forget the quotes, which would lead to a crash when doing…
rustyhu
  • 1,912
  • 19
  • 28
11
votes
1 answer

How to use numba.jit with methods

Using numba.jit in python. I can convert normal functions to jit-type and run: from numba import jit def sum(a, b): return a+b func = jit(sum) print(func(1, 2)) How to do this to methods? Something like this (this doesn't work and I know…
Abhor
  • 301
  • 1
  • 4
  • 11
1
2
3
20 21