functions in c

5
FUNCTIONS

Upload: trisha-marieh

Post on 29-Jan-2016

12 views

Category:

Documents


0 download

DESCRIPTION

Functions in C

TRANSCRIPT

Page 1: Functions in  C

FUNCTIONS

Page 2: Functions in  C

Actual and Formal Parameters

Actual parameters – variables found in the function call whose values will be passed to the formal parameters

Formal parameters – variables found in the function header that will receive values from the actual parameters

Page 3: Functions in  C

#include<stdio.h>

Main()

{

int area,x,y;

x=25;y=10;

Area=Compute(x,y);

Printf(“%d”,area);

}

Compute(int L, int W)

{

int a;

A=L*W;

return a;

}

Actual parameters

Formal parameters

Page 4: Functions in  C

Call by value and pass by value

Call by value or pass by value – the values of the actual parameters are passed to the formal parameters. Changes that happen to the values of the formal parameters inside the function will not affect the values of the actual parameters

Page 5: Functions in  C

#include<stdio.h>

main()

{

clrscr();

x-=10;y=5;

printf(%d %d\n”,x,y);

pass(x,y);

printf(%d %d\n”,x,y);

getch();

}

pass(int a, int b);{ a= a+5;b=b*2;printf(“%d %d\n”,a,b);}