Header Ads Widget

Ticker

6/recent/ticker-posts

Types of user define function in c.

 There are four type of user define function :--

(i) with argument-with return.
(ii) without argument -with return.
(iii) with argument - without return.
(iv) without argument -without return.

1. with argument -with return :-
                                                        In this type,  function  takes argument and return some value.
#include<stdio.h>
// Global declaration of sum
int sum(int,int); 
int main()
{
     int a,b,c;
     printf("Enter the value of a and b");
     scanf("%d%d",&a,&b);
     c=sum(a,b);   // function calling 
     printf("sum of a and b is %d",c);
     return 0;
 
}
// End of main function 
// function definition of sum

int sum(int x,int y)
//where x and y are formal argument 
{
    int z;
    z=x+y;
    return z;
}
Output:-

Enter the value of a and b
10 5
sum is 15

 
2) Without argument-with return:-
                                                               In this type,  function  does not takes any argument and but it return some value.

#include<stdio.h>
// Global declaration of sum
int sum(void); 
int main()
{
    int c;
// function calling 
// here we do not pass any argument
    c=sum();   
    printf("sum is %d",c);
    return 0;
 
}
// End of main function 
// function definition of sum

int sum(void) 
{
    int a,b,z;
    printf("Enter the value of a and b");
    scanf("%d%d",&a,&b);
    z=a+b;
    return z;
}

output:-

Enter the value of a and b
10 5
sum is 15

<<Pre--Example of function                           With Argument without return-Next>>



Recommended Post:

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments