Parameter is defined as the type of data that a me PDF

Title Parameter is defined as the type of data that a me
Author jon seeeee
Course Programming 1
Institution University of the People
Pages 2
File Size 29.4 KB
File Type PDF
Total Downloads 33
Total Views 127

Summary

Download Parameter is defined as the type of data that a me PDF


Description

Parameter is defined as the type of data that a method receives. A parameter refers to the type of data being passed more specifically to an identifier which identifies the type of data. When calling a subroutine and passing values to calling area, both formal and actual parameter are used. In subroutine calling, actual parameters are used while in formal parameter, parameters are defined in the form. Parameters are used in the method body and at runtime will take on the values of argument. Parameters are also used by functions, methods, subroutines to accept values and it is the input that a method takes. Parameter will pass the information to a method. When a parameter is passed to a method, a copy of the parameter is made for use within the method body. Formal parameter is parameter used in the method , a variable and appears in function or method. Actual parameter is the parameter passed to the method when it is called, a variable or expression and appears in the function or method in the calling environment. Differences between formal parameter and actual parameter: Formal parameter: - Is a simple identifier and must be a name. Does not have a value and takes the value from the form from the actual parameter. The formal parameter is the variable found in the function definition. - Situated in caller method. It is the identifier used in the callee's method and callee is the function invoked by the caller. - Values of formal parameter can be altered by function. - Variables defined by function that receives the value. - In function definition statement, it contains data type. - At the time of call, in function definition actual parameter is assigned to formal parameter.

Actual parameter: - Contain a value and is specified by an expression. Actual parameter is the actual input passed. - Written in called function. Actual parameter is the identifier used by the caller when invoking the call and the caller is the function that is invoking the function call. - Values of actual parameter cannot be altered. - Passed by the caller. - Values passed to the function when it is involved. - In function calling statement, it does not contain data type. - Values or expression pass in the call when a function is called.

Example: public class Main { // Method definition public static int multiply(int a, int b, int c) {

return a * b* c ; } public static void main(String[] args) { // Where the method multiplication is used int length = 10; int breadth = 2; int height = 5; int volume = multiply(length, breadth, height); System.out.println("Value is" + volume); } } Output: Value is100 In this example, int a ,int b and int c are the formal parameters because they do not have any value. They have to take the value from length, breadth and height. The value of length, breadth and height are known as the actual parameters. The formal parameter in this example contain the value that is passed by the actual parameter. A call method, called multiply with 3 parameters namely a, b and c and these parameters are known formal parameters. The multiply function from another function passes the 3 parameters namely length, breadth and height which are the actual parameters. 538 words...


Similar Free PDFs