Discuss the concept of parameters 1 PDF

Title Discuss the concept of parameters 1
Author jon seeeee
Course Programming 1
Institution University of the People
Pages 1
File Size 33.7 KB
File Type PDF
Total Downloads 92
Total Views 149

Summary

Download Discuss the concept of parameters 1 PDF


Description

Discuss the concept of parameters. What are parameters for? What is the difference between formal parameters and actual parameters? Give an example in Java code that illustrates formal parameters and actual parameters. The term parameter (sometimes called formal parameter) is often used to refer to the variable as found in the function definition, while argument (sometimes called actual parameter) refers to the actual input supplied at function call. Parameters appear in procedure definitions; arguments appear in procedure calls. 1. Formal parameter variables are allocated memory units only when they are called, and at the end of the call, the allocated memory units are immediately eliminated. Therefore, formal parameters are only valid inside the function. After the function call ends, the formal parameter variable cannot be used after returning to the main calling function. 2. The actual parameters can be constants, variables, expressions, functions, etc. No matter what type of quantities the actual parameters are, they must have certain values when making function calls. In order to transfer these values to the formal parameters. Therefore, it is important to use assignment, input and other methods to make the parameter obtain a certain value in advance. 3. The actual parameters and formal parameters should be strictly consistent in number, type, and order, otherwise an error of type mismatch will occur. 4. In the mechanism of general value-calling, only actual parameters can be transmitted to formal parameters, but the values of formal parameters cannot be reversely transmitted to actual parameters. Therefore, during the function call, the value of the formal parameter changes, but the value in the actual parameter does not change Example of Formal parameters and actual parameters in Java public class differenceactualandformalparameter { //invoke (call) the method int number1 = 30; int number2 = 70;

int sum = add(number1, number2); // this is an example of actual parameter //method define

private int add(int number1, int number2) { // this is an example of formal parameter...


Similar Free PDFs