1 / 14

FUNCTIONS

FUNCTIONS. 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. Definition of function.

gitel
Download Presentation

FUNCTIONS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FUNCTIONS

  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. Definition of function 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 , sqrtetc • 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() FUNCTIONS Built-In Functions User-Defined Functions 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. #include<stdio.h> 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 Gowtham@freshupdates.in

  8. Category of Functions (Based on Return values and passing Arguments) • NO ARGUMENT NO RETURN VALUES • ARGUMENT BUT NO RETURN VALUES • NO ARGUMENT WITH RETURN VALUES • WITH ARGUMENT WITH RETURN VALUES BACK

  9. /* To perform Addition of two numbers */ /* NO ARGUMENT NO RETURN VALUES */ #include<stdio.h> void add(); void add() void main() { { inta,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<stdio.h> void add(int,int); void main() { intx,y; printf("Enter two number"); scanf("\t\t%d %d",&x,&y); add(x,y); /* Actual Arguments */ } void add(inta,int b) /* Formal Arguments */ { int c=a+b; printf("\t\tThe C Value is %d",c); } BACK

  11. Return Expression 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. /* To perform Addition of two numbers Without Argument and With Return values */ #include<stdio.h> #include<conio.h> int add(); //declaration void main() { int c; c=add(); /* Return Variable - c */ printf("The sum of two numbers is %d",c); } int add() { inta,b,c; printf("Enter two Numbers="); scanf("%d %d",&a,&b); c=a+b; return(c); } BACK Gowtham@freshupdates.in

  13. /* To perform Addition of two numbers With Argument and With Return values */ #include<stdio.h> 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(intx,int y) /* Formal arguments */ { int c; c=x+y; return(c); } Gowtham@freshupdates.in

  14. THANKS BACK

More Related