Upcoming SlideShare
×

Like this presentation? Why not share!

# Function C

## on Sep 06, 2011

• 959 views

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

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

### Views

Total Views
959
Views on SlideShare
959
Embed Views
0

Likes
0
28
0

No embeds

### Report content

• Comment goes here.
Are you sure you want to

## Function CPresentation Transcript

• 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
• FUNCTION Mr.Warawut Khangkhan Chapter 4 Function 3
• 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
• BINARY FUNCTION ORSTANDARD FUNCTION Mr.Warawut Khangkhan Chapter 4 Function 5
• 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
• 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
• 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
• 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
• USER DEFINEDFUNCTION Mr.Warawut Khangkhan Chapter 4 Function 10
• 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
• User defined function (Cont.) (Cont.) F F F F F FF F F F F F Mr.Warawut Khangkhan Chapter 4 Function 12
• FORMAT FUNCTIONDECLARATION Mr.Warawut Khangkhan Chapter 4 Function 13
• 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
• 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
• TYPE OF FUNCTIONS Mr.Warawut Khangkhan Chapter 4 Function 16
• 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
• 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
• 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
• 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
• 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
• THE SCORE OFVARIABLES Mr.Warawut Khangkhan Chapter 4 Function 22
• (The score of variables) C F F F F 2 ◦ global ◦ local Mr.Warawut Khangkhan Chapter 4 Function 23
• 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
• global (Cont.) F global F Fglobal F F Mr.Warawut Khangkhan Chapter 4 Function 25
• 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