Functions and Parameters C++ - Reading Assignment

#101
  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?

    Parameters are the key mechanism by which functions can be written in a reusable way, as it allows them to perform tasks without knowing the specific input values ahead of time.

1 Like

#102

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?
Parameters are the key mechanism by which functions can be written in a reusable way, which allows them to perform tasks without knowing the specific input values ahead of time.

1 Like

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

  2. Parameters are the key mechanism by which functions can be written in a reusable way, as it allows them to perform tasks without knowing the specific input values ahead of time.

1 Like

#104
  1. A function parameter is written between the parentheses in the function, and can be used in the function.
  2. Function doesn’t need parameters but it makes the function more easier to understand.
1 Like

#105
  1. What is a function parameter?
    A function parameter is a variable used in the function. It is placed between the paranthesis after the function identifier. Variable values are provided by the caller.

  2. Why do functions need parameters?
    A function needs parameters if any values are to be passed to the function. This is how we enable input to the function. The input values in this case would be called arguments.

1 Like

#106
  1. A function parameter is a variable used in a function where the value is provided by the caller of the function.
  2. Functions need parameters because parameters are the key mechanism by which functions can be written in a reusable way, as it allows them to perform tasks without knowing the specific input values ahead of time. Those input values are passed in as arguments by the caller.
1 Like

#107
double doubleNumber(double n)
{
    return n+n;
}

int main()
{
    cout << doubleNumber(3) << endl;
}
1 Like

#108
  1. Functions are program modules wrapped around the unique parameters which behaves as variables shaping the result/return

  2. It provides reusability to the functions.

1 Like

#109

Hello @ivan and dear Community,

1. What is a function parameter?

Using parameters will allow you to pass arguments whilst calling a function.

2. Why do functions need parameters?

Functions DON’T NEED parameters. :wink: Parameters affecting the behaviour of the function and it’s output.

3. Quiz code:

#include <iostream>
#include <string>

int doubleNumber(int input) {
    return input * 2;
}

std::string getInput() {
    std::string x;
    std::cin >> x;
    return x;
}

int main() {
    
    std::cout << getInput() << std::endl;

    return 0;
}

Kind regards
Kevin

0 Likes

#110
  1. What is a function parameter?
    private variables that need to be filled with values in order to run, values are provided by the caller of the function.
  2. Why do functions need parameters?
    To be able to execute theyr procedure if those statements are coded in a way that extra data is need it to be filled before it can start.
0 Likes

#111
  1. What is a function parameter?
    A parameter is like a placeholder. A function parameter is variable that needs to be used by the function to perform some calculation or function. e.g. in code below “r” is the parameter which is then used to calculate the area of circle.
    double circleArea(double r) {
    return 3.141 * r * r;
    }

  2. Why do functions need parameters?
    Without parameters functions won’t be much useful e.g.
    void printHello(void) {
    cout <<“Hello world” <<endl;
    }

    will print “Hello world” to console but there isn’t any useful task being done here.

0 Likes

#112

Are you sure functions don’t need parameters? Without parameters functions are almost useless.

0 Likes

#113
  1. What is a function parameter?
    Values passed to the function that could be jused within the function.
  2. Why do functions need parameters?
    Parameter is not mandatory, but it gives information to the functions. Which can simplify code without creating global variable to use inside other functions.
0 Likes

#114
  1. What is a function parameter? It is a variable used in a function where the value is provided by the caller of the function.
  2. Why do functions need parameters? They are needed because they are the key mechanism by which functions can be written in a reusable way.
0 Likes

#115
  1. What is a function parameter?
  • Function parameters are variables that a function can use as inputs
  1. Why do functions need parameters?
  • Function parameters are used inside functions as the only way that a function can access external information
0 Likes

#116
  1. What is a function parameter?
    A variable used in a function. They work similar to variables defined inside the function, but they are always initialized with a value provided by the caller of the function.

  2. Why do functions need parameters?
    To ensure that the functions have a correct input.

0 Likes

#117

Think about the following questions while reading:

  1. What is a function parameter? A specific value required by the function
  2. Why do functions need parameters? Some functions require a value passed on from elsewhere
0 Likes

#118
  1. It is the variable that the function will work with. In the function body, there will be statements operating with the parameter, that will lead us to the return value.

  2. So we can make use of a value that we obtained beforehand, which we feed to the function to operate with. It is silly to define it everytime and often we can’t even do that, we just want to call the function upon a value that was obtained in some other parts of our code.

0 Likes

#119
1. What is a function parameter?

It is variable used in the function. They differ from variables defined in a function because they are passed through by the user himself. Parameters are defined inside the parentheses of the function, like so for example int add(int x, int y). x and y are the function parameters and are of type int.

2. Why do functions need parameters?

Functions need parameters to pass arguments to one another. Parameters are not mandatory though

0 Likes

#120
  1. A function parameter. is a variable used in a function.
  2. Parameters allows to take input from the user and also reuse the code. Parameter allows to perform a task without knowing specific input values at the beginning.
0 Likes