Modern form
return-type function-name (var-type arg1, var-type arg2, ...)
In both forms, the return-type is the data type of the function returned
value. If functions do not return values, then return-type must be declared
as void. The function-name is the name of this function and is equalent
to a global variable of all other functions. The arguments, arg1, arg2 etc,
are the variables to be used in this function. Their data type must be
specified. These variables are defined as formal parameters to receive
values when the function is called.
→
Function declaration
// classic form
return-type function-name (arg1, arg2, ...);
// modern form
return-type function-name (var-type arg1, var-type arg2,...);
→
Function definition
// classic form
return-type function-name (arg1, arg2, ...)
var-type arg1;
var-type arg2;
{
statements;
}
// modern form
return-type function-name (var-type arg1, var-type arg2, ...)
{
statements;
}
→
Passing arguments to functions
There are two methods for passing arguments to functions.
•
Pass by value. This method copies the argument values to the correspond-
ing formal parameters of the function. Any changes to the formal parame-
ters will not affect the original values of the corresponding variables in
the calling routine.
•
Pass by reference. In this method, the address of the argument is copied
to the formal parameters of the function. Within the function, the formal
parameters can access the actual variables within the calling routine.
Hence, changes to the formal parameters can be made to the variables.
→
Returning values from functions
By using the return statement, a function can return a value to the calling
routine. The returned value must be of a data type specified within the
function definition. If return-type is void, it means no return value,
Chapter 9 Holtek C Language
99
Содержание HT-IDE
Страница 11: ...P a r t I Integrated Development Environment Part I Integrated Development Environment 1 ...
Страница 12: ...HT IDE User s Guide 2 ...
Страница 20: ...Fig 1 6 Fig 1 7 HT IDE User s Guide 10 ...
Страница 24: ...HT IDE User s Guide 14 ...
Страница 70: ...HT IDE User s Guide 60 ...
Страница 76: ...HT IDE User s Guide 66 ...
Страница 92: ...HT IDE User s Guide 82 ...
Страница 93: ...P a r t I I Development Language and Tools Part II Development Language and Tools 83 ...
Страница 94: ...HT IDE User s Guide 84 ...
Страница 148: ...HT IDE User s Guide 138 ...
Страница 150: ...Fig 12 1 Fig 12 2 HT IDE User s Guide 140 ...
Страница 154: ...HT IDE User s Guide 144 ...
Страница 192: ...HT IDE User s Guide 182 ...
Страница 194: ...HT IDE User s Guide 184 ...
Страница 218: ...HT IDE User s Guide 208 ...
Страница 235: ...P a r t V Appendix Part V Appendix 225 ...
Страница 236: ...HT IDE User s Guide 226 ...
Страница 250: ...HT IDE User s Guide 240 ...