Functions and its types (Theory)

 Functions are block of codes which divides large programs into sub-programs, A function is a block of code which can execute itself again and again by calling itself.

syntax: 

                add()                     //function declaration

                void main()

                {

                       add();            //function call

                }

                add()                   //function definition

                                                                   

                int a,b,c;

                a=10;

                b=20;

                c= a+b;

                printf("addition = %d ",c );

               }

There are two types of function 

1. Pre-defined functions: these function are known to compiler, since they are already present in compiler libraries, which just need to be called for execution like: printf, scanf, main() etc.

2. User-defined functions: these function are defined by the user

they are of two types:

1.default function: every function without parameters is default function because default function can not change it's values or statements, once declared they are default for the whole program.

   syntax: 

                add()                   

               {                                                     

                int a,b,c;

                a=10;

                b=20;

                c= a+b;

                printf("addition = %d ",c );

               } 

                void main()

                {

                       add();           

                }

2. (a) function with parameters: these function have parameters and arguments that can be changed any time while calling functions.

   (b) function with multiple parameters: these function have multiple parameters and arguments.

syntax: 

               add(int a,int b)                   

               {                                                     

                printf("addition = %d ",a+b );

               } 

                void main()

                {

                       add(20,30);           

                }

No comments:

Post a Comment