Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.
Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.
In this section, we explore the difference between formal parameters, which are placeholders in a function definition, and actual parameters that are the real values supplied to a function when it is invoked. Understanding this distinction is essential for effectively using functions in programming.
In programming, particularly within functions, we encounter two types of parameters: formal and actual parameters. Formal parameters are declared in the function signature; they act as variables that accept values when the function is invoked. On the other hand, actual parameters are the real values that are passed to these formal parameters during the function call.
void greet(String name)
, name
is a formal parameter used to receive the input when greet
is called.Dive deep into the subject with an immersive audiobook experience.
Signup and Enroll to the course for listening the Audio Book
● Formal parameters: Defined in the function declaration.
Formal parameters are the variables that are declared in the function definition. They act as placeholders that receive values when the function is called. For instance, if we define a function to add two numbers, we can say add(int a, int b)
. Here, a
and b
are the formal parameters that are specified in the function declaration. They help the function know what data it will work with.
Imagine you are baking cookies. The recipe calls for ingredients (like flour and sugar) but does not specify quantities. When you decide how many cookies to make, you fill in those ingredient amounts. In this scenario, the recipe is like the function definition, and the ingredient quantities represent the formal parameters.
Signup and Enroll to the course for listening the Audio Book
● Actual parameters: Passed when the function is called.
Actual parameters are the real values that are passed to the function when it is called. Using our previous example, if you call the function add(5, 3)
, the actual parameters are 5
and 3
. These values are inserted into the formal parameters a
and b
during the execution of the function, allowing the function to perform its task using these specific inputs.
Continuing with the baking analogy, think of the actual parameters as the specific amounts of ingredients you choose when you bake cookies. You might take 2 cups of flour and 1 cup of sugar. These numbers are your actual parameters, which you use to make the cookies based on the recipe.