Presentation is loading. Please wait.

Presentation is loading. Please wait.

Definition of function Types of Function Built-in User Defined Catagories of Function No argument No return value Argument but No return value No argument.

Similar presentations


Presentation on theme: "Definition of function Types of Function Built-in User Defined Catagories of Function No argument No return value Argument but No return value No argument."— Presentation transcript:

1

2 Definition of function Types of Function Built-in User Defined Catagories of Function No argument No return value Argument but No return value No argument with return value argument with return value

3 A function is a self contained block of code that performs a particular task. C functions can be classified into two categories namely Built-In function and User Defined function BACK

4  Built-In Function/Library Function Library function are not required to be written by users. examples of library functions are scanf, printf, sqrt etc User Defined Function User Defined Function User Defined Function have to be developed by the user. main is an example of user defined function. The use of User Defined Function allows a large program into a number of smaller self contained components, each of which has some unique purpose BACK

5 scanf() printf() getc() putc() A series of Instructions that are to be executed more than once

6 USER DEFINED FUNCTION : SYNTAX : retu_datatype func_name(arguments) { Body of the function statements; return; } call the function from main() : syntax : func_name(arguments );

7 Gowtham@freshupdates.in #include void hello() //definition { printf(" Welcome to functions\n"); printf("Good Morning\n"); } void main() { clrscr(); printf("Main, Welcome to functions\n"); hello(); //calling printf("Bye"); getch(); } BACK

8  NO ARGUMENT NO RETURN VALUES  ARGUMENT BUT NO RETURN VALUES  NO ARGUMENT WITH RETURN VALUES  WITH ARGUMENT WITH RETURN VALUES (Based on Return values and passing Arguments) BACK

9 /* To perform Addition of two numbers */ /* NO ARGUMENT NO RETURN VALUES */ #include void add();void add() void main(){ {int a,b,c; add(); printf("Enter two numbers\n"); printf("Prg ends"); scanf("%d%d",&a,&b); add(); c=a+b; }printf("The sum is %d\n",c); } BACK

10 /* To perform Addition of two numbers */ /* WITH ARGUMENT BUT NO RETURN VALUES*/ #include void add(int,int); void main() { int x,y; printf("Enter two number"); scanf("\t\t%d %d",&x,&y); add(x,y); /* Actual Arguments */ } void add(int a,int b) /* Formal Arguments */ { int c=a+b; printf("\t\tThe C Value is %d",c); } BACK

11  The return statement is used to return from a function.  It causes execution to return to the point at which the call to the function was made.  The return statement can have a value with it, which it returns to the program

12 Gowtham@freshupdates.in /* To perform Addition of two numbers Without Argument and With Return values */ #include int add(); //declaration void main() { int c; c=add(); /* Return Variable - c */ printf("The sum of two numbers is %d",c); } int add() { int a,b,c; printf("Enter two Numbers="); scanf("%d %d",&a,&b); c=a+b; return(c); } BACK

13 Gowtham@freshupdates.in /* To perform Addition of two numbers With Argument and With Return values */ #include int add(int,int); //Function prototype declaration void main() { int c; printf("Enter two Numbers="); scanf("%d %d",&a,&b); c=add(a,b); /* Actual Arguments */ printf("The sum of two numbers is %d",c); } int add(int x,int y) /* Formal arguments */ { int c; c=x+y; return(c); }

14 BACK


Download ppt "Definition of function Types of Function Built-in User Defined Catagories of Function No argument No return value Argument but No return value No argument."

Similar presentations


Ads by Google