Functions and Parameters C++ - Reading Assignment

1. What is a function parameter? A function parameter is a variable used in a function where the value is provided by the caller of the function.

2. Why do functions need parameters? Functions do need parameters so you can perform tasks without initially having to know the specific input values.

1 Like
  1. What is a function parameter?
    A variable used in a function. The function parameters operates the same as a variable, with the difference that a value is initialized by the caller of the function.
  2. Why do functions need parameters?
    A function need parameters so that it has data to work with, initialized from a caller function with a value as the argument.
1 Like
  1. What is a function parameter?
    A function parameter is an input value that is passed from the caller function to the called function. The parameters are assigned values before they are passed to the called functioned. To the called function, the parameters passed work as if they were defined and assigned a value within that function.

For example, the double hours, the double minutes and the double rate are the parameter from function main to function CalculatePay function.

double CalculatePay(double hours, double minutes, double rate){
double percent_minutes = minutes/60;
double pay = (hours + percent_minutes) * rate;
return pay;
}
int main()
{
double hours{38};
double minutes{30};
double rate{50.25};
double myPay = CalculatePay(hours,minutes,rate);
cout<< "My pay for the week is " << myPay << ‘\n’;
return 0;
}
6. Why do functions need parameters?
Functions need parameters to perform the required task; in the example above parameters are used to calculate pay. They work as if the variables were assigned within the called function.

1 Like
  1. What is a function parameter? A function parameter is a variable used in a function, which is always initialized by a value provided by the caller of the function.
  2. Why do functions need parameters? It is a way to pass the value of variable num to function printDouble so that printDouble can use that value in the function body.
1 Like
  1. A function parameter is a variable used in a function.
  2. Function parameters are used to pass information to a functions.
1 Like
  1. What is a function parameter?
    This a value that is passed to a function so it can be used in that function’s body.

  2. Why do functions need parameters?
    Functions don’t necessarily need parameters. They need parameters if they need to access data obtained somewhere in the program or we want the function to do certain different things based on variable inputs.

1 Like

1. What is a function parameter?
Variable used in a function
2. Why do functions need parameters?
To give value to the caller

1 Like

You mean to the called function? :slight_smile:

2 Likes
  1. What is a function parameter?
    A function parameter is a variable used in a function. When a function is called a value is given. We call that value an argument.

  2. Why do functions need parameters?
    How does posi trac on a Plymouth work?
    It just does!
    Functions however do need parameters so that when it is called a variable can be assigned to the function.

1 Like
  1. What is a function parameter?

A function parameter is a variables used in a function, this work mostly as a regular variable but the its value is only initialised by the caller function. Parameter are placed in between the parentheses uses when a function is defined and called.

  1. Why do functions need parameters?

Parameters allow a the function to have precise values to work with in case it is needed, otherwise there can be also function which don’t necessarily require any parameter.

1 Like
  1. A function parameter is a variable used inside function, passed as a input argument by caller.
  2. The function need parameters to do some kind of arithmetic computing, for example. Work like as kind as black box, given an input, has some result.
1 Like
  1. What is a function parameter?
    A function parameter is a variable used in a function. This variable represents some kind of value which is given to the function when it’s executed.

  2. Why do functions need parameters?
    Sometimes the values that will be given to a function are not known at the beginning of an execution. Parameters are placeholders for values, that are given to the function later, when they are known.

1 Like
  • Values you use when calling a function, example sumNumbers(2,2) = 4
  • So that they have something to work on
1 Like

What is a function parameter?
A function parameter is a variable used in a function.

Why do functions need parameters?
A parameter is part of the function definition. A parameter allows us to pass values to our functions.

1 Like
  • What is a function parameter?

A function parameter is a variable used in a function.

  • Why do functions need parameters?

To pass the value of variable abc to function whatever so that whatever can use that value in the function body.

1 Like
  1. a function parameter is the variable used inside the function to perform it’s task.
  2. without any parameters, the function has no data to perform its task with. Some functions that have no return value (void), don’t necessarily need a parameter if it’s just executing a simple task, like printing to the console for example.
1 Like

void functions can actually still have parameters :slight_smile: this just means the function doesn’t return a value back to the caller.

1 Like
  1. It is a variable passed to the function.
  2. The parameters are input variables, the function works on them and may pass a result as return. We do this to make functions more useful.
1 Like
  1. Function parameters work almost identically to variables defined inside the function, but with one difference: they are always initialized with a value provided by the caller of the function.
  2. Parameters helps to provide values outside the function to the function.
1 Like
  1. A function parameter is a variable of a function, and is initialized with a value provided by the caller.

  2. Functions need parameters so that they can compute calculations ahead of time, without needing to know any intialized inputs or outputs.

1 Like