No Return With Argument Function in C


In C programming, a function that takes one or more arguments but does not return a value is called a void function. The syntax for defining a 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 'void' keyword is used as the return type to indicate that the function does not return any value. The function_name is the name of the function, and the argument1, argument2, ... are the input parameters that the function takes.
  • A void function with arguments can be called by providing the values for the arguments in the function call:

           function_name(value1, value2, ...);

  • This program is a simple C program that demonstrates how to define and call a void function in C. The program defines a void function called add that takes two integer parameters, x and y, and adds them together. The function then prints the result of the addition.
  • The main function first 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 result of the addition is then printed to the console.

Source Code

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

Output

Enter The Value of A & B : 23
34

Total : 57

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