Upcoming SlideShare
×

Like this presentation? Why not share!

# Functions16.12

## on Jan 13, 2012

• 203 views

Study notes on Functions

Study notes on Functions

### Views

Total Views
203
Views on SlideShare
203
Embed Views
0

Likes
0
7
0

No embeds

### Report content

• Comment goes here.
Are you sure you want to

## Functions16.12Presentation Transcript

• Functions in C A brief study
• Functions• Function is a self-contained block or a sub- program of one or more statements that performs a special task when called.
• Example of functions• Hotel management – Front Office – Reservation – Housekeeping – Telephone
• Hotel management
• HotelCustomer() { House_keeping(); //Function call }House_keeping() //Function definition { Cleans rooms; }
• HotelCustomer() //calling function { House_keeping(); //Function call }House_keeping() //called function { Cleans rooms; }
• Add two numbersmain(){ int a,b; int c; printf(“Enter the value of a”); scanf(“%d”,&a); printf(“Enter the value of b”); scanf(“%d”,&b); c=a+b; printf(“Answer is:%d”,c);}
• Add two numbers using functionsmain(){ add(x,y) int a,b; { int c; z=x+y; printf(“Enter the value of a”); printf(“%d”,z); scanf(“%d”,&a); } printf(“Enter the value of b”); scanf(“%d”,&b); add(a,b);}
• Arguments/Parameters• Arguments are used mostly in functions.• it can be any input parameter which a function can use to do its work.• Example: sin(x) sin is a function x is its argument.
• Arguments/Parameters• Actual arguments: • Arguments of calling function• Formal arguments: • Arguments of called function
• Add two numbers using functionsmain() formal arguments{ add(x,y) int a,b; { int c; z=x+y; printf(“Enter the value of a”); printf(“%d”,z); scanf(“%d”,&a); } printf(“Enter the value of b”); scanf(“%d”,&b); add(a,b); //function call} actual arguments