Return With Argument Function in C


In C programming, a function that takes one or more arguments and returns a value is called a non-void function. The syntax for defining a non-void function with arguments is as follows:

        Syntax :
           return_type function_name ( data_type argument1, data_type argument2, ... ) // Function Definition
           {
                 // body of Statement ;
           }

  • Here, the return_type specifies the data type of the value that the function will return. The function_name is the name of the function, and the argument1, argument2, ... are the input parameters that the function takes. The value is the value that the function returns.
  • A non-void function with arguments can be called by providing the values for the arguments in the function call:

                 result = function_name(value1, value2, ...) ;

  • The value returned by the function is stored in the variable result.
  • This program is a simple C program that demonstrates how to define and call a non-void function in C. The program defines a non-void function called add that takes two integer arguments x and y and returns the sum of these two integers. The function uses the return statement to return the result of the addition.
  • The main function prompts the user to enter two integers, a and b, which are then passed as arguments to the add function when it is called. The add function uses these arguments as its x and y parameters and performs the addition. The returned value from the function is then assigned to the variable 'a' and the program then prints the result of the addition to the console.
  • This program shows how to define a non-void function, call it and pass the arguments to it and how the function uses the arguments and returns a value. It also demonstrates how the return statement is used to return a value from a function to the calling function.

Source Code

//Return With Argument Function in C
#include<stdio.h>
int add(int,int);
int main()
{
    int a,b;
    printf("\nEnter The Value of A & B : ");
    scanf("%d%d",&a,&b);
    a=add(a,b);
    printf("\nTotal : %d",a);
    return 0;
}
 
int add(int x,int y)
{
    return x+y;
}
 
To download raw file Click Here

Output

Enter The Value of A & B : 2
9

Total : 11

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C