Monday, October 21, 2019
Define Parameters in Computer Programming
Define Parameters in Computer Programming Parameters identify values that are passed into a function. For example, a function to add three numbers might have three parameters. A function has a name, and it can be called from other points of a program. When that happens, the information passed is called an argument. Modern programming languages typically allow functions to have several parameters. Function Parameters Each function parameter has a type followed by an identifier, andà eachà parameter is separated from the next parameter by a comma. The parameters pass arguments to the function. When a program calls a function, all the parameters are variables. The value of each of the resulting arguments is copied into its matching parameter in a process call pass by value. The program uses parameters and returned values to create functions that take data as input, make a calculation with it and return the value to the caller. The Difference Between Functions and Arguments The terms parameter and argument are sometimes used interchangeably. However, parameter refers to the type and identifier, and arguments are the values passed to the function. In the following C example,à int aà andà int bà are parameters, whileà 5à andà 3à are the arguments passed to the function. int addition (int a, int b){à int r;à rab;à return r;} int main (){à int z;à z addition (5,3);à cout The result is z;} Value of Using Parameters Parameters allow a function to perform tasks without knowing the specific input values ahead of time.Parameters are indispensable components of functions, which programmers use to divide their code into logical blocks.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment