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
11
votes
3 answers

Aren't a[][] and (*a)[] equivalent as function parameters?

Function prototype void foo(int n, int a[][]); gives error about incomplete type while void foo(int n, int (*a)[]); compiles. As per the decay rule int a[][] is equivalent to int (*a)[] in this case and therefore int (*a)[] should also give…
haccks
  • 104,019
  • 25
  • 176
  • 264
11
votes
5 answers

What is the easiest and most compact way to create a IEnumerable or ICollection?

So, many times we have a function that accepts an IEnumerable or ICollection as a parameter. In cases where we have single items, but no collection to hold them, we must create a collection before passing them to the function, like: T o1, o2,…
Ashley Simpson
  • 383
  • 1
  • 6
  • 16
11
votes
4 answers

Will a reference bound to a function parameter prolong the lifetime of that temporary?

I have this code (simplified version): const int& function( const int& param ) { return param; } const int& reference = function( 10 ); //use reference I can't quite decide to which extent C++03 Standard $12.2/5 wording The temporary to…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
11
votes
3 answers

assignment operator within function parameter C++

I'm studying data structures (List, Stack, Queue), and this part of code is confusing me. ListNode( const Object& theElement = Object(), ListNode * node = NULL); template ListNode::ListNode( const Object& theElement,…
Harry Cho
  • 2,309
  • 4
  • 20
  • 28
10
votes
2 answers

Variadic templates without function parameters

Can I use variadic templates without using the template parameters as function parameters? When I use them, it compiles: #include using namespace std; template void print(First first) { cout << 1 <<…
Heinzi
  • 5,793
  • 4
  • 40
  • 69
9
votes
3 answers

Passing functions as arguments in C++

I'm a bit rusty in C++ and I'm switching after a year of python. Naturally I would like to translate the laziness coming from python to C++. I just discovered rot13 and I'm all excited about it. I found 3 ways of doing it and I wanted to do a little…
Pella86
  • 500
  • 3
  • 10
  • 18
9
votes
3 answers

How can I use the edit_post function in PyTumblr?

I am trying to edit some posts in my tumblr blog using PyTumblr and the edit_post function, but I can't figure out exactly what parameters are needed. I try to put the tags parameter but it's not accepted. I have tried this: client =…
IordanouGiannis
  • 4,149
  • 16
  • 65
  • 99
8
votes
5 answers

Does C support optional null parameters?

In Python, I'm used to things like def send_command(command, modifier = None): and then the modifier argument is optional, and the absence of the argument can be differentiated from an argument of 0. Is there similar functionality in C? I'm…
endolith
  • 25,479
  • 34
  • 128
  • 192
8
votes
2 answers

Constructing std::pair of integers with a variable using post-increment

I tried constructing pairs of integers where the second integer is greater than the first by 1: 1 2 2 3 3 4 Using both std::make_pair and the constructor like so: std::make_pair(n, n++); However, this results in the pairs being in reverse: 2 1 3…
Pesho_T
  • 814
  • 1
  • 6
  • 18
8
votes
2 answers

Is there a simple way to call a function with default arguments?

Here is a function declaration with default arguments: void func(int a = 1,int b = 1,...,int x = 1) How can avoid calling func(1,1,...,2) when I only want to set the x parameter and for the rest with the previous default params? For example, just…
Y.Lex
  • 241
  • 1
  • 7
8
votes
1 answer

How to change the color of function parameters in visual studio code c++?

Environment Visual Studio Code 1.25 for linux (ubuntu 16.04). Theme VisualStudio Dark. currently I'm using visual studio code 1.25 in Ubuntu 16.04 for writing c++ code. I want to change the color of function parameters like in the visual studio…
dk13
  • 1,461
  • 4
  • 20
  • 47
8
votes
4 answers

c# Enum Function Parameters

As a follow on from this question. How can I call a function and pass in an Enum? For example I have the following code: enum e1 { //... } public void test() { myFunc( e1 ); } public void myFunc( Enum e ) { var names =…
TK.
  • 46,577
  • 46
  • 119
  • 147
8
votes
2 answers

Use function argument as name for new data frame in R

this is very simple, but I have searched and failed to find a solution for this small problem. I want to use the argument of a function as the name for a new data frame, for example: assign.dataset<-function(dataname){ x<-c(1,2,3) …
AP30
  • 505
  • 7
  • 18
7
votes
1 answer

Determining the Parameter Types of an Undefined Function

I've recently learned that I cannot: Take the address of an undefined function Take the address of a templatized function with a type it would fail to compile for But I've also recently learned that I can call decltype to get the return type of…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
7
votes
2 answers

scala way to define functions accepting a List of different numeric types

I have the following problem: I have a function which takes a List[Double] as parameter, performs some arithmetic operations on the elements of the list and than return the result. I would like the function also to accept List[Int]. Here is an…
Filippo Tabusso
  • 601
  • 3
  • 10
  • 16
1 2
3
20 21