103
C-Control Pro Mega Series
© 2008 Conrad Electronic
void main(void)
{
// function func1 will be called up twice
func1();
func1();
}
Parameter Passing
In order to enable functions to be flexibly used they can be set up parametric. To do this the
parameters for the function are separated by commas and passed in parenthesis after the function
name. Similar to the variables declaration first the data type and then the parameter name are
stated. If no parameter is passed then void has to be set into the parenthesis.
An example:
void func1(word param1, float param2)
{
Msg_WriteHex(param1);
// first parameter output
Msg_WriteFloat(param2);
// second parameter output
}
Similar to local variables passed parameters are only visible within the function itself.
In order to call up function func1 by use of the parameters the parameters for call up should be
written in the same succession as they have been defined in func1. If the function does not get
parameters the parenthesis will stay empty.
void main(void)
{
word a;
float f;
func1(
128
,
12.0
);
// you can passs numerical constants
a=
100
;
f=
12.0
;
func1(a+
28
,f);
// or yet variables too and even numerical expressions
}
When calling up a function all parameters must always be stated. The following call up is
inadmissible:
func1();
// func1 gets 2 parameters!
func1(
128
);
// func1 gets 2 parameters!
Return Parameters
It is not only possible to pass parameters. A function can also offer a return value. The data type of
this value is during function definition entered ahead of the function name. If no value needs to be
returned the data type used will be void.
int func1(int a)
Содержание C-Control Pro Mega Series
Страница 1: ... 2008 Conrad Electronic C Control Pro Mega Series ...
Страница 9: ...VIII Inhalt 2008 Conrad Electronic ...
Страница 10: ...Part 1 ...
Страница 17: ...Part 2 ...
Страница 23: ...Part 3 ...
Страница 41: ...32 Hardware 2008 Conrad Electronic 3 3 5 3 Component Parts Plan ...
Страница 57: ...48 Hardware 2008 Conrad Electronic 3 4 5 3 Component Parts Plan ...
Страница 58: ...Part 4 ...
Страница 91: ...82 IDE 2008 Conrad Electronic ...
Страница 92: ...Part 5 ...
Страница 135: ...126 Compiler 2008 Conrad Electronic 31 1F US 63 3F 95 5F _ 127 7F DEL ...
Страница 136: ...Part 6 ...
Страница 231: ...Part 7 ...
Страница 240: ......