In programming, argument(parameter) refers to data this is passed to function(function definition) while calling function.
In above example, two variables, num1 and num2 are passed to function during function call. These arguments are known as actual arguments. The value of num1 and num2 are initialized to variables a and b respectively. These arguments a and b are called formal arguments. This is demonstrated in figure below:
Notes on passing arguments
In the above program, the value of add inside user-defined function is returned to the calling function. The value is then stored to a variable sum. Notice that, the variable returned, that is, add is of type
In above example, two variables, num1 and num2 are passed to function during function call. These arguments are known as actual arguments. The value of num1 and num2 are initialized to variables a and b respectively. These arguments a and b are called formal arguments. This is demonstrated in figure below:
Notes on passing arguments
- The numbers of actual arguments and formals argument should be same. (Exception: Function Overloading)
- The type of first actual argument should match the type of first formal argument. Similarly, type of second actual argument should match the type of second formal argument and so on.
- You may call function without passing any argument. The number(s) of argument passed to a function depends on how programmer want to solve the problem.
- In above program, both arguments are of
int
type. But it's not necessary to have both arguments of same type.
Return Statement
A function can return single value to the calling program using return statement. In the above program, the value of add is returned from user-defined function to the calling program using statement below:return add;The figure below demonstrates the working of return statement.
In the above program, the value of add inside user-defined function is returned to the calling function. The value is then stored to a variable sum. Notice that, the variable returned, that is, add is of type
int
and also sum is of int type. Also notice that, the return type of a function is defined in function declarator int add(int a,int b)
. The int
before add(int a,int b)
means that function should return a value of type int
. If no value is returned to the calling function then, void
should be used
1 comments:
Click here for commentsPassing Arguments To Function ~ System Help Line >>>>> Download Now
>>>>> Download Full
Passing Arguments To Function ~ System Help Line >>>>> Download LINK
>>>>> Download Now
Passing Arguments To Function ~ System Help Line >>>>> Download Full
>>>>> Download LINK WZ
Show Konversi KodeHide Konversi Kode Show EmoticonHide Emoticon