Function is part of program to work specific task and its place is separate with program who call it. On C programming language, function can be grouped into two, are library function or function has been available on Turbo C and function is made by self. Syntax for a function is:
type_output_function name_of_fungsi(fungsi_parameter_variable);
{
...
}
Function is made by self placed before main() function, so that program syntax will look:
type_output_function name_of_fungsi(fungsi_parameter_variable);
{
...
}
main()
{
...
}
Example we want to make function of addition 2 integers. Output type = int, example name of function is w, parameter variables: int x dan int y, so that its syntax is:
int w(int x, int y)
{
int z;
z=x+y;
}
main()
{
int a,b,c;
a=1;b=2;
c=w(a,b);
printf("%d",c);
getch();
}
On the example above, w function is called by c variable, w function can be used more than once by different variable:
int w(int x, int y)
{
int z;
z=x+y;
}
main()
{
int a,b,c,d,e,f;
a=1;b=2;
c=w(a,b);
printf("%d",c);
d=17;e=10;
f=w(d,e);
printf("\n%d",f);
getch();
}
On this example, w function is called twice
But when be tried to clear type_output_function so that program syntax becomes:
w(int x, int y)
{
int z;
z=x+y;
}
main()
{
int a,b,c,d,e,f;
a=1;b=2;
c=w(a,b);
printf("%d",c);
d=17;e=10;
f=w(d,e);
printf("\n%d",f);
getch();
}
in fact, program is still normal and accurate,
Hopefully useful...
Reference: Thanks to http://onestring.wordpress.com
type_output_function name_of_fungsi(fungsi_parameter_variable);
{
...
}
Function is made by self placed before main() function, so that program syntax will look:
type_output_function name_of_fungsi(fungsi_parameter_variable);
{
...
}
main()
{
...
}
Example we want to make function of addition 2 integers. Output type = int, example name of function is w, parameter variables: int x dan int y, so that its syntax is:
int w(int x, int y)
{
int z;
z=x+y;
}
main()
{
int a,b,c;
a=1;b=2;
c=w(a,b);
printf("%d",c);
getch();
}
On the example above, w function is called by c variable, w function can be used more than once by different variable:
int w(int x, int y)
{
int z;
z=x+y;
}
main()
{
int a,b,c,d,e,f;
a=1;b=2;
c=w(a,b);
printf("%d",c);
d=17;e=10;
f=w(d,e);
printf("\n%d",f);
getch();
}
On this example, w function is called twice
But when be tried to clear type_output_function so that program syntax becomes:
w(int x, int y)
{
int z;
z=x+y;
}
main()
{
int a,b,c,d,e,f;
a=1;b=2;
c=w(a,b);
printf("%d",c);
d=17;e=10;
f=w(d,e);
printf("\n%d",f);
getch();
}
in fact, program is still normal and accurate,
Hopefully useful...
Reference: Thanks to http://onestring.wordpress.com
0 komentar:
Posting Komentar