Our Blog Contain Detail about Some Technical Aspect like Programming, Blogger, Tools and Tip, Suggestion, Motivational, Health, Program in C and Java, Html

What do you mean by user defined Function | Explain the function definition, function declaration and function call with syntax and suitable example?

Q What do you mean by user defined Function | Explain the function definition, function declaration and function call with syntax and suitable example? 



Ans: A Function is a set of instruction which perform specific task. We can create a function according to our need using C. that function will be a user defined function. So, a function which is created by user to solve a particular problem is called user defined function.

Function Definition: -  In function definition, the user writes the code into the body of the function.

the syntax of function definition: -

                        return_Typefunction_name(argument_1, argument_2,....){

//statements

//body of the function

}

for example:-

                        int fact( int n){

                                    if(n<=1){

                                                return 1;

                                    }

                                    else{

                                                return fact( n-1 );

                                    }

                        }


Function declaration :- A function declaration is simply creating a frame for a function. It contains function name , list of arguments and its return type.

The syntax for function declaration:-

           return_Type function_Name(argument_1,argument_2,......);

For example:-

                        int swap( int a , int b);


Funtion calling :- When a function is called, the the code written in the body of that function is executed. Basically after the function is called the control of flow goes to the function and it start executing.

Syntax for function calling:-

                        function_name(argument_1,argument_2,……);

For example:-

                        swap(a,b);


Simple Example For Function Definition , Declaration  And Function Calling 

#include<stdio.h>

#include<coinio.h>

void Display(); // here we declare the function

void main()

{

Display(); // here we call the function

}

void Display()  //here we define the function 

{

printf("Hello Friend");

}

There are following type of user defined Function

1. function with no return type and no Parameter

2. function with no return type but have Parameter

3. function with return type and Parameter.

Share:

No comments:

Post a Comment

Translate

Followers

Email Subscription

Enter your email address:

Delivered by FeedBurner

Recent Posts

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.