A parameter is an optional list of parameters that you define both pass information into the procedure and send information out of procedure back to the calling program. Parameter is also known as argument. When you define a parameter, you also specify the way in which it can be used. There are three different modes of parameter or argument.
What is the difference between formal parameters and actual parameters? Give an example in Java code that illustrates formal parameters and actual parameters. Parameters Parameters are variables listed as part of a method declaration. Formal parameters are the parameters as they are known in the function definition. Actual parameters (also known asarguments) are what are passed by the caller.
1. Actual Parameters :
The arguments that are passed in a function call are called actual arguments. These arguments are defined in the calling function. These are the variables or expressions referenced in the parameter list of a subprogram call. There is no need to specify datatype in actual parameter.
Example :
2. Formal Parameters :
These are the variables or expressions referenced in the parameter list of a subprogram specification. The datatype of the receiving value must be defined. The scope of formal arguments is local to the function definition in which they are used.
Difference Between Actual Parameter And Formal Parameter In Java With Example
Example :
Difference between Actual and Formal Parameters :
C# Formal Parameter
Actual Parameters | Formal Parameters |
---|---|
When a function is called, the values (expressions) that are passed in the function call are called the arguments or actual parameters. | The parameter used in function definition statement which contain data type on its time of declaration is called formal parameter. |
These are the variables or expressions referenced in the parameter list of a subprogram call. | These are the variables or expressions referenced in the parameter list of a subprogram specification. |
Actual Parameters are the parameters which are in calling subprogram. | Formal Parameters are the parameters which are in called subprogram. |
There is no need to specify datatype in actual parameter. | The datatype of the receiving value must be defined. |
The parameters are written in function call are known as actual parameters. | The parameters are written in function definition are known as formal parameters. |
Actual Parameters can be constant values or variable names. | Formal Parameters can be treated as local variables of a function in which they are used in the function header. |
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the 'Improve Article' button below.
|