2. Contents
Binary function or Standard function.
User defined function.
Format function declaration.
Type of functions.
The score of variables.
Mr.Warawut Khangkhan Chapter 4 Function 2
3. FUNCTION
Mr.Warawut Khangkhan Chapter 4 Function 3
4. Function
F F F
main( ) F F F
F C F F2
F (Library Function) F F
F F F F F (User
Defined Function)
Mr.Warawut Khangkhan Chapter 4 Function 4
6. Binary function or Standard
function
F F F C
F F F F F F
,F F F
F
F
Mr.Warawut Khangkhan Chapter 4 Function 6
7. Binary function or Standard
function (Cont.)
F C F F .h
F header file F F
F header file F F
F F F math.h
F F F F string.h
Mr.Warawut Khangkhan Chapter 4 Function 7
8. Binary function or Standard
function (Cont.)
F F F
#include <header file> F F
F C F F
F F F header file F
F F F F
F F F
Mr.Warawut Khangkhan Chapter 4 Function 8
9. Example lib_func.c
#include <stdio.h>
#include <math.h>
int main( ) {
int x, y;
printf(“Enter number: “);
scanf(“%d”, &x);
y = sqrt(x);
printf(“Square root of %d = %d”, x, y);
system(“PAUSE”);
return 0;
}
Mr.Warawut Khangkhan Chapter 4 Function 9
14. F C
(Format function declaration)
type function-name ( type arg-1, type arg-2, … ) {
local variable declaration;
statement-1;
statement-2;
statement-3;
…
statement-n;
return ( value );
}
Mr.Warawut Khangkhan Chapter 4 Function 14
15. Example ex_func.c
#include <stdio.h> void main( ) {
line( );
void line( ) {
int i; printf(“Welcome to
for (i=0; i<30; i++) C Programmingn”);
printf(“*”); line( );
printf(“n”); }
}
Mr.Warawut Khangkhan Chapter 4 Function 15
17. F
(Type of functions)
F F F3
F F / F F
F F F F
F F F F
Mr.Warawut Khangkhan Chapter 4 Function 17
18. F F / F F
F F F F F F
F F (Argument) F F F
F F F F F F
F F FF F F F F
F
Mr.Warawut Khangkhan Chapter 4 Function 18
19. F F
F F F F F
F F (Argument) F F F
F F F F F F F
F F F F F3 int, float
int F F F F F F
F F F F F
F int, float int
Mr.Warawut Khangkhan Chapter 4 Function 19
20. F F F F
F F F F
F F F F F F F
F F F F
F F F F F F
F F F
Mr.Warawut Khangkhan Chapter 4 Function 20
21. F F F F
(Cont.)
variable = function-name ( arg-1, arg-2,
… );
F F F F F F return
F F F
Mr.Warawut Khangkhan Chapter 4 Function 21