Upcoming SlideShare
×

# Function C

945 views

Published on

การเขียนฟังก์ชันในภาษา C

Published in: Sports
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
945
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
33
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Function C

2. 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. 3. FUNCTION Mr.Warawut Khangkhan Chapter 4 Function 3
4. 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
5. 5. BINARY FUNCTION ORSTANDARD FUNCTION Mr.Warawut Khangkhan Chapter 4 Function 5
6. 6. Binary function or Standardfunction F F F C F F F F F F ,F F F F F Mr.Warawut Khangkhan Chapter 4 Function 6
7. 7. Binary function or Standardfunction (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. 8. Binary function or Standardfunction (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. 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
10. 10. USER DEFINEDFUNCTION Mr.Warawut Khangkhan Chapter 4 Function 10
11. 11. F F(User defined function) F C F F F F F F F C F F F F F F F F F F F F F F F F F F Mr.Warawut Khangkhan Chapter 4 Function 11
12. 12. User defined function (Cont.) (Cont.) F F F F F FF F F F F F Mr.Warawut Khangkhan Chapter 4 Function 12
13. 13. FORMAT FUNCTIONDECLARATION Mr.Warawut Khangkhan Chapter 4 Function 13
14. 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. 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
16. 16. TYPE OF FUNCTIONS Mr.Warawut Khangkhan Chapter 4 Function 16
17. 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. 18. F F / F F F F F F F F F F (Argument) F F F F F F F F FF F FF F F F F F Mr.Warawut Khangkhan Chapter 4 Function 18
19. 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, floatint F F F F F F F F F F F F int, float int Mr.Warawut Khangkhan Chapter 4 Function 19
20. 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. 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
22. 22. THE SCORE OFVARIABLES Mr.Warawut Khangkhan Chapter 4 Function 22
23. 23. (The score of variables) C F F F F 2 ◦ global ◦ local Mr.Warawut Khangkhan Chapter 4 Function 23
24. 24. global global F F external F F F F global F F F F F F F F F F F F FF Mr.Warawut Khangkhan Chapter 4 Function 24
25. 25. global (Cont.) F global F Fglobal F F Mr.Warawut Khangkhan Chapter 4 Function 25
26. 26. local local F Fautomatic F F F local F F F F F F F F F F F F local F F F F F F F F F local F F Mr.Warawut Khangkhan Chapter 4 Function 26