Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
ayub ali
Courses Plus Student 723 Pointswhat is an argument?
and show me how it looks like by an example and very clear, thank you.
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! An argument is what we pass to a function when we call it. Let's take a look at a really basic function.
public int addNumbers(int num1, int num2) {
return num1 + num2;
}
This defines a function named addNumbers and it has parameters named num1 and num2. This will add any two integers we send in. We send in the numbers by calling the function:
int results = addNumbers(15, 21);
This line calls the function or tells it to run/execute. The numbers 15 and 21 are our arguments. They are what are being sent to the function. When the function runs, the first argument (15) will be assigned to the variable(parameter) num1 and the second argument(21) will be assigned to the second variable(parameter) num2. The value will then be returned by the function and assigned to results, which in this case will be a value of 36.
Hope this helps!
ayub ali
Courses Plus Student 723 Pointsayub ali
Courses Plus Student 723 Pointsit did ,thank you